Technical: File System Event Abstraction
Refactor the file watcher to use a semantic event layer (
FileSystemEventenum) instead of directly matching on thenotifycrate's low-level events. This enables unit testing of event handling logic without filesystem mocks, simplifies the 140-line pattern-matching block into clean semantic matches, decouples from thenotifycrate for easier upgrades or replacement, and creates a foundation for smarter features like addon-aware change detection, intelligent debouncing, and batch operation coalescing.
Arguments for Keeping the Abstraction
1. Decoupling from notify crate
Currently the code is tightly coupled to
notify::EventKindmatching (lines 192-341)If
notifychanges its API or you switch to a different file watcher crate, you'd have to rewrite all the event handling logicWith
FileSystemEvent, you'd only change the translation layer once
2. Simpler event handling
The current match statement is ~140 lines of gnarly pattern matching on
notify::EventKindvariantsWith the abstraction, event handlers would be cleaner:
match event { FileSystemEvent::DirectoryCreated(path) => { /* handle */ } FileSystemEvent::FileRemoved(path) => { /* handle */ } // ... }
3. Testability
You can't easily unit test code that depends on
notify::Eventwithout mocking the filesystemWith
FileSystemEvent, you can create test events trivially and test your handling logic in isolation
4. Semantic clarity
notifyhasCreate(CreateKind::Any),Remove(RemoveKind::Folder), etc. - you're already translating these to semantic strings like"directory_created"The enum would formalize this translation and make the code's intent clearer
5. Future extensibility
You might want custom events like
AddonFolderChanged(Uuid, String)that carry more context than raw pathsAn abstraction layer gives you a place to add that semantic enrichment
Log in to comment and vote
No comments yet
Be the first to share your thoughts.