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.
This commit is contained in:
T. R. Bernstein
2026-03-12 10:54:06 +01:00
parent b41b82bd0f
commit a8d7fb017f
2 changed files with 22 additions and 4 deletions

View File

@@ -0,0 +1,18 @@
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]
}
}