Skip to content

Conversation

@echobt
Copy link
Contributor

@echobt echobt commented Jan 20, 2026

Description

The process_files() function in src/watcher.rs had a time-of-check to time-of-use (TOCTOU) race condition. A file could be deleted between the path.exists() check and the subsequent read_to_string() call, causing silent failures.

This PR addresses the issue by handling ErrorKind::NotFound when reading the file. If the file is not found during the read operation, it is treated as deleted and removed from the index.

Changes

  • Modified process_files in src/watcher.rs to match on read_to_string result.
  • Added a match arm for ErrorKind::NotFound to handle the race condition.
  • When NotFound occurs, the code now attempts to remove the file from the database and logs the race condition handling.

Verification

  • I have verified that the code compiles.
  • Existing tests pass.
  • The logic specifically targets the described race condition where path.exists() returns true but the file is gone by the time read_to_string() is called.

During the file processing in process_files, there was a time-of-check to time-of-use
(TOCTOU) race condition where a file could be deleted between path.exists() check and
read_to_string() call.

This commit handles ErrorKind::NotFound error when reading the file. If the file is not found,
we assume it was deleted and remove it from the index, similar to how explicit deletion events are handled.

Fixes PlatformNetwork/bounty-challenge#90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants