Files
swift-inotify/Sources/Inotify/InotifyWatchManager.swift
T. R. Bernstein a8d7fb017f Add data structure for watch descriptor management
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.
2026-03-12 11:32:29 +01:00

19 lines
534 B
Swift

struct InotifyWatchManager {
private var watchPaths: [CInt: String] = [:]
private var activeWatches: Set<CInt> = []
mutating func add(_ path: String, withId watchDescriptor: CInt) {
self.watchPaths[watchDescriptor] = path
self.activeWatches.insert(watchDescriptor)
}
mutating func remove(forId watchDescriptor: CInt) {
self.watchPaths.removeValue(forKey: watchDescriptor)
self.activeWatches.remove(watchDescriptor)
}
func path(forId watchDescriptor: CInt) -> String? {
return self.watchPaths[watchDescriptor]
}
}