Files
swift-inotify/Sources/Inotify/Inotify.docc/Inotify.md
T
T. R. Bernstein 8af25be549
Docs / docs (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
Exclude items by shell pattern as well as by name
Patterns such as `.*` or `@*` are matched against an item's own name
with `fnmatch`, in the same places as excluded names: resolving a
tree, extending a watch to a directory that appears later, and
delivering events. Dependents that prune large trees can now skip
whole families of directories without listing each name.
2026-09-16 11:21:45 +02:00

47 lines
1.7 KiB
Markdown

# ``Inotify``
Monitor filesystem events on Linux using modern Swift concurrency.
## Overview
The Inotify library wraps the Linux [inotify](https://man7.org/linux/man-pages/man7/inotify.7.html) API in a Swift-native interface built around actors and async sequences. You create an ``Inotify/Inotify`` actor, add watches for the paths you care about, and iterate over the ``Inotify/Inotify/events`` property to receive ``InotifyEvent`` values as they occur.
```swift
let inotify = try Inotify()
try inotify.addWatch(path: "/tmp/inbox", mask: [.create, .modify])
for await event in await inotify.events {
print("\(event.mask) at \(event.path)")
}
```
Beyond single-directory watches, the library provides two higher-level methods for monitoring entire directory trees:
- ``Inotify/Inotify/addRecursiveWatch(forDirectory:mask:)`` installs watches on every existing subdirectory at setup time.
- ``Inotify/Inotify/addWatchWithAutomaticSubtreeWatching(forDirectory:mask:)`` does the same **and** automatically watches subdirectories that are created after setup.
You can also exclude certain file or directory names, exactly or by shell pattern, so that they are skipped during directory resolution and silently dropped from the event stream. See ``Inotify/Inotify/exclude(names:)``, ``Inotify/Inotify/exclude(patterns:)`` and <doc:WatchingDirectoryTrees> for details.
All public types conform to `Sendable`, so they can be safely passed across concurrency boundaries.
## Topics
### Essentials
- ``Inotify/Inotify``
- ``InotifyEvent``
- ``InotifyEventMask``
### Articles
- <doc:WatchingDirectoryTrees>
### Errors
- ``InotifyError``
- ``DirectoryResolverError``
### Low-Level Types
- ``RawInotifyEvent``