The stream's element is now the enum InotifyEvent, and the struct that
describes a change to a watched item is FileSystemEvent. A queue
overflow was an event with descriptor -1 and an empty path that every
consumer had to know about; as a case, the compiler makes them handle
it. The enum is also where failed watches of a growing tree will be
reported, since no call site can catch them.
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.
Automatic subtree watching only reacted to `CREATE`, so a directory
moved in from elsewhere stayed unwatched. It is now handled like a
created one. Items that already exist in such a directory never
produce kernel events; they are reported with the same event kind
and `synthesized` set to `true`, so consumers can treat them as
newly appeared.
A directory moved out of a watched tree kept its kernel watches, so
later changes inside it were reported under the old path. Its
watches and those of its subdirectories are now removed on
`MOVED_FROM`. Watches the kernel reports as `IGNORED` are forgotten
as well, so a reused descriptor number cannot map to a stale path.
`IN_Q_OVERFLOW` arrives with watch descriptor -1, so the path lookup
failed and the event was silently discarded. It is now delivered
with an empty path so consumers can rescan after the kernel dropped
events.
Events were buffered with `bufferingNewest(512)`, so a burst of
changes silently lost all but the newest 512 events whenever the
consumer lagged. The stream now buffers without limit, and
`init(bufferingPolicy:)` lets callers choose a bounded policy.
`deinit` closed the inotify descriptor while its dispatch source was
still active. The kernel drops the epoll registration on close, but
libdispatch keeps its own; an instance created afterwards that reuses
the descriptor number could inherit that stale state and never
receive events. Roughly one test run in three lost a single event
this way.
The reader is now cancelled in `deinit` and the descriptor closed in
its cancel handler, as libdispatch requires.
Properties of actors are implicitly isolated. To be able to read the
events stream from any concurrent context, we need to declare it
nonisolated. And as AsyncStream conforms to Sendable, it is safe to make
both events and the private eventStream nonisolated.
For watching whole trees - a change which is upcoming - the watch
descriptor IDs will have to be managed in multiple lists. The
InotifyWatchManager encapsulates the managment logic within a nice API.
Instead of using hardcoded fixed width integers, use C integer types.
As the actual integer size of C depends on the implementation, even if
it is often 32bit, we use the C integer types to guard against cases,
where that is not the case.
Each inotify instance produces events for paths in its watch list. Each
item in the watch list is identified by its watch descriptor. Different
paths can be watched for different events.