views:

35

answers:

1

I setup a FSEvent that runs well but it keeps reporting the same event each time I launch the app.

Ex:

My FSEvent monitor directory is:

Test/

...and there are three files:

test1, test2, test3

However, after I deleted test1 in my FSEvent Directory, it keeps telling me that test1 has been deleted every time I run the program instead of just the one time after the deletion.

I cleaned all managedObjects in my context and deleted the whole directory but the event keeps being reported.

What should I do such that it only tells me right after the deletion and then never again?

Thanks a lot!

+1  A: 

File system event are persistent between launches. They are tracked by the file system itself, not the app. That is why you keep seeing the event every time you launch.

I believe you have to call FSEventsPurgeEventsForDeviceUpToEventId or the like to clear the events.

Take that with a grain of salt. I haven't fiddled with it much.

Edit:

From File System Events Programming Guide:

To work with persistent events, your application should regularly store the last event ID that it processes. Then, when it needs to go back and see what files have changed, it only needs to look at events that occurred after the last known event. To obtain all events since a particular event in the past, you pass the event ID in the sinceWhen argument to FSEventStreamCreate or FSEventStreamCreateRelativeToDevice.] [On a per-device basis, you can also easily use a timestamp to determine which events to include. To do this, you must first call FSEventsGetLastEventIdForDeviceBeforeTime to obtain the last event ID sinceWhen argument to FSEventStreamCreateRelativeToDevice.

I think the important thing to remember is that the file system events are not actually stored or even related to app that is observing them. They exist independently of the app in the file system itself. In practice, several different apps could be set to observe the same event.

TechZen
The docs for `FSEventsPurgeEventsForDeviceUpToEventId` say "Can only be called by the root user".
JWWalker
Yes, I was misremembering. See my edit for the correct answer.
TechZen
Thank you so much! I am really a newbie.. Q_Q
Frost