Best Cocoa way to monitor several thousand files for move, delete and rename?

165 views Asked by At

I have an app that keeps a database of files located on the user's machine or perhaps on networked volumes that may or may not be online. This database can potentially be several thousand files located in different folders. What is the best way to monitor them to receive notification when a file's name is changed, or it moves or is deleted?

I have used FSEvents before for a single directory but I am guessing that it does not scale well to a few thousand individual files. What about using kqueues?

I might be able to try to maintain a dynamic list of folders trying to encompass all the files with as few folders as possible, but this means reading though the full list and trying to figure out common ancestors etc.

Thoughts or suggestions?

1

There are 1 answers

1
cacau On

From Apple's docs:

If you are monitoring a large hierarchy of content, you should use file system events instead, however, because kernel queues are somewhat more complex than kernel events, and can be more resource intensive because of the additional user-kernel communication involved.

https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/FSEvents_ProgGuide/KernelQueues/KernelQueues.html#//apple_ref/doc/uid/TP40005289-CH5-SW2