Is there a good objc library wrapper for File System Events/kqueue that handles recursive watching for me?

StackOverflow https://stackoverflow.com/questions/5987129

Question

I want to write an OSX (Snow Leopard) app that receives notifications when files within a specific directory are changed, and I want access to the path of the specific file that was changed.

I know I can do this using either File System Events or kqueue. The former doesn't provide the details of which specific file changed (requiring me to build a snapshot of the directory I'm watching and then scan it to find out which file changed). The latter doesn't support recursive watching (requiring me to recursively add watches to every file and directory within the parent directory).

I've had a look for libraries that handle the snapshot/recursion fun for me, but can't find any. UKKQueue looks like a good wrapper for the low level kqueue stuff, but doesn't seem to do recursion. Same for GTMFileSystemKQueue. SCEvents looks like a good wrapper for File System Events but doesn't seem to handle finding out the specific file that changed.

Is there a library that does what I want and is suitable for an objc project for either of these technologies?

Was it helpful?

Solution

I ended up using GTMFileSystemKQueue after I found out how easy it is to recursively iterate over a directory in objc:

// Create a directory enumerator for the given top level directory
NSDirectoryEnumerator *de = [[NSFileManager defaultManager] enumeratorAtPath:dir];

// Add a kqueue on every file and folder below the top level
NSString *file;
while ((file = [de nextObject])) {
    [[GTMFileSystemKQueue alloc] initWithPath:[dir stringByAppendingString:file]
                                    forEvents:kGTMFileSystemKQueueAllEvents
                                acrossReplace:YES
                                       target:self
                                       action:@selector(fileSystemKQueue:events:)];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top