Re: Best Technique for Watched folders ?
Re: Best Technique for Watched folders ?
- Subject: Re: Best Technique for Watched folders ?
- From: Mark Gilbert <email@hidden>
- Date: Tue, 5 May 2009 22:48:02 +0100
Thanks Jean-Daniel
I did start looking at kqueue but it all seemed rather obscure.
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...
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.
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.
The key issues seem to be:
- What are we watching for ? - new files, changed files ? renamed
files ?
- How do we find them ? - bulk search, iteration ?
- 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 ?
- What happens as our folder gets full up....?
- 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).
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden