Files
swift-inotify/Sources/Inotify/InotifyError.swift
T
T. R. Bernstein c037302c01
Docs / docs (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
Report the directories a growing tree could not watch
Extending an automatically watched tree to a new directory swallowed
every error, so a reached watch limit or an unreadable directory left
part of the tree unwatched without any sign. No call of the consumer is
running at that moment, so the failures now arrive in the event stream
as InotifyEvent.watchFailed, after the event that triggered the
extension. The library watches what it can first: a reached limit ends
the attempt, an unreadable directory is skipped with its subtree, and a
directory that vanished in between is not reported.

The buffer now carries the library's own events next to the kernel's,
which keeps them in order and hides the stream's element type. The
test runner drops root's DAC capabilities so that an unreadable
directory can be tested.
2026-09-19 00:56:31 +02:00

28 lines
1.0 KiB
Swift

import CInotify
public enum InotifyError: Error, Sendable, Hashable, CustomStringConvertible {
case initFailed(errno: Int32)
case addWatchFailed(path: String, errno: Int32)
case removeWatchFailed(watchDescriptor: Int32, errno: Int32)
/// The directory could not be listed, so its subdirectories are unknown.
case listDirectoryFailed(path: String, errno: Int32)
public var description: String {
switch self {
case .initFailed(let code):
"inotify_init1 failed: \(readableErrno(code))"
case .addWatchFailed(let path, let code):
"inotify_add_watch failed for '\(path)': \(readableErrno(code))"
case .removeWatchFailed(let wd, let code):
"inotify_rm_watch failed for wd \(wd): \(readableErrno(code))"
case .listDirectoryFailed(let path, let code):
"listing '\(path)' failed: \(readableErrno(code))"
}
}
private func readableErrno(_ code: Int32) -> String {
guard let message = cinotify_error_message(code) else { return "errno \(code)" }
return String(cString: message) + " (errno \(code))"
}
}