Re: Notification of file system modification arrives too early?
Re: Notification of file system modification arrives too early?
- Subject: Re: Notification of file system modification arrives too early?
- From: Uli Kusterer <email@hidden>
- Date: Fri, 28 May 2010 12:30:10 +0200
On May 28, 2010, at 12:05 PM, Antonio Nunes wrote:
> My app is set to observe a folder for changes to its contents (...) I get the impression the notification happens as soon as the file transfer into the watched directory begins, and my worker thread is ready and starts loading the file before it has been fully transferred. Hence the failure to create a PDFDocument from the file.
Yes. A KQueue only tells you when a *change* happens, i.e. an individual write operation.
> Is there a way to check whether the file has been fully transferred, or, even better, to get notified only when the file transfer has been completed?
The heuristic most people use is to wait a little time (a few seconds is usually enough) and only start processing a file if a new write notification hasn't arrived in the meantime. I usually use my UKPushbackMessenger for that purpose (see http://github.com/uliwitness/UliKit/blob/master/UKPushbackMessenger.h and http://github.com/uliwitness/UliKit/blob/master/UKPushbackMessenger.m).
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden