Noitidart
Noitidart

Reputation: 37238

Detect old file name and new file name via FSEventsFramework

I am using FSEventsFramework to monitor directories for changes. I was wondering if my logic here is sound, for detecting old file name and new name after a rename.

Is this true?

Thanks

Upvotes: 1

Views: 369

Answers (1)

mahal tertin
mahal tertin

Reputation: 3416

As far as I experienced it, your assumption is not always true. On FSEventStreamCreate you will pass a latency as well as a flag for the meaning of the latency kFSEventStreamCreateFlagNoDefer. Therefore the events may or may not come in the same callback. Furthermore there are different ways the file can be renamed. Some Filesystem-APIs actually rename the file while keeping the inode like mv, others like NSDocument create a new inode. Sometimes you will receive kFSEventStreamEventFlagItemRenamed in the callback, sometimes not.

EDIT: Alternatives to FSEvents are Kernel Queues and NSFileCoordinator

FSEvents are somehow not fully documented in the API-Docs. Have a look at the header file FSEvent.h, there is more to read there.

Then to easily see what is going on for a rename, run your app and do some renaming with Finder, with terminal mv as well as in a document based app using the small triangle right to the filename.

Upvotes: 2

Related Questions