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.
19 lines
534 B
Swift
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]
|
|
}
|
|
}
|