Expand description
§WatchFile
§File: Indexing/Watch/WatchFile.rs
§Role in Air Architecture
Provides file watching functionality for the File Indexer service, handling file system events for incremental index updates.
§Primary Responsibility
Handle file system change events and trigger index updates for created, modified, and deleted files.
§Secondary Responsibilities
- File creation event handling
- File modification event handling
- File deletion event handling
- Directory change event handling
- Event debouncing for rapid changes
§Dependencies
External Crates:
notify- File system watchingtokio- Async runtime for event handling
Internal Modules:
crate::Result- Error handling typecrate::AirError- Error typessuper::super::FileIndex- Index structure definitionssuper::super::Store::UpdateIndex- Index update operations
§Dependents
Indexing::Background::StartWatcher- Watcher setup and managementIndexing::mod::FileIndexer- Main file indexer implementation
§VSCode Pattern Reference
Inspired by VSCode’s file watching in
src/vs/base/node/watcher/
§Security Considerations
- Path validation before watching
- Symbolic link following disabled
- Permission checking on watch paths
§Performance Considerations
- Event debouncing prevents excessive updates
- Batch processing of multiple events
- Efficient event filtering
§Error Handling Strategy
Event operations log warnings for individual errors and continue, ensuring a single event failure doesn’t stop the watcher.
§Thread Safety
Event handlers acquire write locks on shared state and process events asynchronously to avoid blocking the watcher loop.
Structs§
- Debounced
Event Handler - Debounced file change handler
- Processed
Change - Describes a processed file change
Enums§
- File
Change Type - File change type for debouncing
- Processed
Change Result - Result of processing a debounced change
Functions§
- Event
Kind ToChange Type - Convert notify event kind to FileChangeType
- GetDefault
Ignored Patterns - Get default ignored patterns for file watching
- Handle
File Event - Handle file watcher event for incremental indexing
- Should
Watch Path - Check if a path should be watched (not in ignored paths)
- Validate
Watch Path - Validate that a watch path exists and is accessible