Reputation: 899
I'm trying to understand how to use the kFSEventStreamEventFlagEventIdsWrapped
event flag with FSEvents
.
According to the documentation, the flag is sent to registered instances when the event id counter wraps around, thus rendering previous event id obsolete.
Now let's imagine the following scenario:
FSEvents
in my application;FSEvents
(my application quits for instance), I save the last event id encountered while processing events to be able to replay changes from that id;My question is: How am I supposed to know the counter wrapped around? (Thus requiring me to re-scan the whole directory structure.)
Upvotes: 1
Views: 212
Reputation: 899
I now have an answer directly from Apple.
The scenario was wrong to begin with. When saving the last event id treated, you must also save with it the UUID of the event stream. An event id is valid only for a given event stream, which is identified by its UUID (see FSEventsCopyUUIDForDevice()
).
Whenever the event id counter wraps around, a new event stream UUID is generated. So if you relaunch the app after the event id counter wrapped around, your stored last event id won’t be valid anymore, and you’ll know it as the event stream UUID won’t be the same.
If you encounter the kFSEventStreamEventFlagEventIdsWrapped
flag, it means the counter wrapped around while your app was open. However, there’s nothing particular to be done. You should just be sure to get the new event stream UUID if you want to save the last event id.
Upvotes: 1
Reputation: 22930
If kFSEventStreamEventFlagEventIdsWrapped
is set, it means the 64-bit event ID counter wrapped around. As a result, previously-issued event ID's are no longer valid arguments for the sinceWhen parameter of the FSEventStreamCreate()
functions.[1]
Next time your should use kFSEventStreamEventIdSinceNow
for FSEventStreamEventId
and you must rescan all directory.
Upvotes: 0
Reputation: 6517
EDIT:
Event IDs do not wrap.
Here is why: Suppose your machine generates 1 filesystem event per millisecond. This means it will generate ms_per_year=31536000000 filesystem events per year. So it will take more than 500 million years before the counter will wrap around the 64bit boundary.
>>> ms_per_year = 1000*60*60*24*365
>>> d64 = 2**64
>>> d64/ms_per_year
584942417L
Upvotes: 0