-
Notifications
You must be signed in to change notification settings - Fork 256
Add EventKindMask for filtering filesystem events #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
withzombies
wants to merge
9
commits into
notify-rs:main
Choose a base branch
from
aquilonsecurity:filter-access-events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Change EventKindMask::default() from CORE to ALL to match Config::default().event_kinds() - Add userspace event filtering to PollWatcher via EventEmitter - Filter events in emit_ok() using EventKindMask::matches() - Error events always pass through (not filtered) - Add test verifying CREATE-only mask filters MODIFY events - Add cross-crate consistency test for defaults This is part of the EventKindMask cross-platform filtering feature. PollWatcher now respects the event_kinds config, filtering events before delivery to the user's handler.
Adds userspace event filtering to the kqueue backend by storing the EventKindMask from Config and checking events against it before delivering to the handler. This follows the same pattern established in PollWatcher. - Store event_kinds in EventLoop struct - Pass event_kinds from Config through the constructor chain - Filter OK events before calling handle_event(), errors pass through - Add test for filtering behavior (requires BSD/macOS to run)
Add event filtering to the FSEvents (macOS) backend by calling EventKindMask::matches() before delivering events to the handler. This follows the same pattern established in kqueue and PollWatcher. Changes: - Add event_kinds field to FsEventWatcher and StreamContextInfo - Pass event_kinds from Config through to the callback context - Filter events in callback_impl based on the mask - Add test for filtering behavior
Thread EventKindMask through ReadDirectoryChangesServer and start_read to filter events before delivery. Events that don't match the mask are silently dropped, while errors always pass through.
Change test infrastructure ChannelConfig::default() to use Config::default() which includes EventKindMask::ALL instead of CORE. This ensures tests cover all event types including Access events. Updated inotify tests to use wait_ordered() instead of wait_ordered_exact() where appropriate, since with ALL events we may get directory access events that are timing-dependent. Tests that check for absence of specific events now filter out Access events to focus on the behavior being tested.
kqueue uses userspace filtering via EventKindMask::matches(), only inotify has kernel-level support via WatchMask translation. Updated documentation in: - notify-types/src/event.rs: EventKindMask doc comment - notify/src/config.rs: with_event_kinds() doc comment
Use blocking recv_timeout instead of try_iter to avoid race condition between poll thread processing the message and test collecting events.
|
Would really love this feature to be merged. Should this be on the |
Author
I went with Config because it better fit my use case. I wasn't trying to have a mix of event levels. I think if we want different event levels we could start a few watchers? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds EventKindMask, a bitflags-based type that allows users to configure which event kinds they want to receive. This is configured via Config::with_event_kinds().
This feature allows filtering at the source. On Linux (inotify), filtering happens at the kernel level via WatchMask translation, so unwanted events never reach userspace. On other backends, filtering is applied early in the event pipeline.
Existing users shouldn't see any breaking changes. The default (EventKindMask::ALL) should preserve existing behavior.
Usage
Changes