Implement watch exclusion lists
Some checks failed
Docs / docs (push) Has been cancelled
Docs / deploy (push) Has been cancelled

Allow exclusion of directories when watching recursively.
This commit is contained in:
T. R. Bernstein
2026-03-15 22:30:10 +01:00
parent c87099e4a7
commit 134e4e152d
8 changed files with 115 additions and 25 deletions

View File

@@ -75,6 +75,24 @@ try await inotify.addWatchWithAutomaticSubtreeWatching(
This is the most convenient option when you need full coverage of a growing directory tree.
## Excluding Items
You can tell the `Inotify` actor to ignore certain file or directory names. Excluded names are skipped during recursive directory resolution (so no watch is installed on them) and silently dropped from the event stream:
```swift
let inotify = try Inotify()
// Ignore version-control and build directories
await inotify.exclude(names: ".git", "node_modules", ".build")
try await inotify.addWatchWithAutomaticSubtreeWatching(
forDirectory: "/home/user/project",
mask: [.create, .modify, .delete]
)
```
Use `isExcluded(_:)` to check whether a name is currently on the exclusion list.
## Event Masks
`InotifyEventMask` is an `OptionSet` that mirrors the native inotify flags. You can combine them freely.