Re: Best Technique for Watched folders ?
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com -josh On May 5, 2009, at 2:48 PM, Mark Gilbert wrote: Thanks Jean-Daniel I did start looking at kqueue but it all seemed rather obscure. Cheers Mark Gilbert. On 5 May 2009, at 22:41, Jean-Daniel Dupas wrote: Le 5 mai 09 à 22:04, Mark Gilbert a écrit : Folks. The key issues seem to be: - How do we find them ? - bulk search, iteration ? - What happens as our folder gets full up....? _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/jgraessley%40apple.com This email sent to jgraessley@apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... kqueue really isn't that hard and you can use a kqueue with a CFSocket to get notifications on a run loop when the kqueue has an event ready to read. polling is a waste. kqueue will eliminate the need to poll. I think for my starting point I am going to call stat() on the parent folder, that seems pretty reliable to pick up any kind of change in the contents (unless I am kidding myself). I am going to poll that once every few secs. FSEvents looks interesting - thanks for that. I am thinking that for a single folder, which doesnt change much the stat() approach is probably gentle enough not to matter, and its going to save me learning all about FSEvents. Once I spot a change, I will start the hard work, I think that is the bit which is more exotic... For the 3rd time in my life I am about to start writing folder watching code. It's one of those things thats easy to do in a half hearted manner, but somewhat complicated to do in an efficient and comprehensive way. I thought I might canvas some ideas from other people before I embark on this next generation. - What are we watching for ? - new files, changed files ? renamed files ? - How do we know which ones have already been processed ? - mod date ? some kind of flag ? - How do we know when its safe to 'trigger' on a file which is being written into the folder ? - How do we do all this efficiently without hammering the file system or the CPU ? I have my own ideas on some of these things, but I wanted to see if anyone else had a strong point of view. In particular whether its a good plan to mark files in some way, and whether this can be keyed automatically into the discovery process. Also, what is the best discovery process ? I am sure Apple would tell us to use event notifications rather than polling the folder, but I have not had much luck figuring out what can be notified and how. I can give you an answer at least about notifications. You can use either the FSEvent API or kevent/kqueue API (or a launchd task and let launchd watching the folder for you). This email sent to site_archiver@lists.apple.com
participants (1)
-
Josh Graessley