Skip to content

Add watch_filtered, filtering paths to watch - #950

Closed
daandemeyer wants to merge 1 commit into
notify-rs:mainfrom
daandemeyer:push-xtzypqtzstty
Closed

Add watch_filtered, filtering paths to watch#950
daandemeyer wants to merge 1 commit into
notify-rs:mainfrom
daandemeyer:push-xtzypqtzstty

Conversation

@daandemeyer

@daandemeyer daandemeyer commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Adds WatchFilter and Watcher::watch_filtered, allowing directories to be excluded when setting up a watch. Implemented for the inotify, fsevents, kqueue, windows, poll, and null backends, with filter support plumbed through Watcher::update_paths, notify-debouncer-full, and the FileIdCache API.

The filter gates directories only: walk-based backends prune excluded directories at scan time and gate directories discovered while watching; FSEvents and Windows suppress matching events at delivery time. File watches are never affected.

Two restrictions keep the semantics simple and the implementation small:

  • Watching a directory the filter itself rejects returns the new ErrorKind::PathExcluded and changes nothing. Symlink roots are checked against their resolved target too.
  • A directory watch carrying a filter must not overlap another directory watch in either direction; such calls are refused with an error. Filters are never merged across watches, so each watch entry carries exactly one filter. Accept-all watches keep the existing overlap semantics, file watches never conflict, and re-watching the same path still replaces the watch (WatchFilter::same_filter identity makes an identical re-watch a no-op).

Based on the filter-watch-targets branch:

  • Add watch_filtered, filtering paths to watch.
  • Add fsevent support and filter newly added paths too.
  • Add support for watch_filtered to Windows.
  • Add filtered watch implementation for kqueue.

@daandemeyer

Copy link
Copy Markdown
Contributor Author

@JohnTitor Any chance you could enable workflows for this PR? The workflows don't run on my fork so I need them enabled here to make sure windows and macos work as expected.

@JohnTitor

Copy link
Copy Markdown
Member

Triggered!

@daandemeyer

Copy link
Copy Markdown
Contributor Author

@JohnTitor Hmm seems you need to reapprove every single time. I'll see if I can find some trivial fix that can already land so I don't have to ask every time

@daandemeyer

Copy link
Copy Markdown
Contributor Author

Opened #951, if you merge that one CI will start working automatically here without needing your approval every time.

@daandemeyer
daandemeyer force-pushed the push-xtzypqtzstty branch 4 times, most recently from 2e2a7ad to 3f6822b Compare July 9, 2026 10:52
@daandemeyer
daandemeyer marked this pull request as ready for review July 9, 2026 10:53
@daandemeyer
daandemeyer force-pushed the push-xtzypqtzstty branch 4 times, most recently from 6eab4f4 to 43cf792 Compare July 9, 2026 15:41
@daandemeyer

Copy link
Copy Markdown
Contributor Author

Should be ready for review now, includes two other commits which I've split out into separate PRs. Will rebase this pr once those are merged. It's a lot of code, but a lot of it is tests, happy to split up into separate commits or PRs if that's preferred.

Adds `WatchFilter` and `Watcher::watch_filtered`, allowing directories to
be excluded when setting up a watch. Implemented for the inotify,
fsevents, kqueue, windows, poll, and null backends, with filter support
plumbed through `Watcher::update_paths`, `notify-debouncer-full`, and the
`FileIdCache` API.

The filter gates directories only: walk-based backends prune excluded
directories at scan time and gate directories discovered while watching;
FSEvents and Windows suppress matching events at delivery time. File
watches are never affected.

Two restrictions keep the semantics simple and the implementation small:

- Watching a directory the filter itself rejects returns the new
  `ErrorKind::PathExcluded` and changes nothing. Symlink roots are
  checked against their resolved target too.
- A directory watch carrying a filter must not overlap another directory
  watch in either direction; such calls are refused with an error.
  Filters are never merged across watches, so each watch entry carries
  exactly one filter. Accept-all watches keep the existing overlap
  semantics, file watches never conflict, and re-watching the same path
  still replaces the watch (`WatchFilter::same_filter` identity makes an
  identical re-watch a no-op).

Based on the filter-watch-targets branch:
- Add `watch_filtered`, filtering paths to watch.
- Add fsevent support and filter newly added paths too.
- Add support for watch_filtered to Windows.
- Add filtered watch implementation for kqueue.

Co-authored-by: Hugo van der Wijst <hvanderwijst@tesla.com>
Signed-off-by: Daan De Meyer <daan@amutable.com>
@daandemeyer

Copy link
Copy Markdown
Contributor Author

Closing so I can open other prs

@daandemeyer daandemeyer closed this Aug 1, 2026
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.

3 participants