1

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.

  • I think on rename, both events are in the same callback.
  • Old file name will have event id X-1
  • New file name will have even id X

Is this true?

Thanks

Noitidart
  • 35,443
  • 37
  • 154
  • 323

1 Answers1

2

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.

mahal tertin
  • 3,239
  • 24
  • 41
  • Thanks mahal, I set the latency to 0 do you think in that case the should come in same callback? But regardless if in same CB do you know if the old/new rename event should be X and X+1 event id? – Noitidart Apr 23 '15 at 18:40
  • Thanks @mahal for your edits! :) Do you mean for kernel queues this: https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/FSEvents_ProgGuide/KernelQueues/KernelQueues.html – Noitidart Apr 24 '15 at 10:03
  • 1
    @Noitidart did this answer help you? if yes, would you like to accept it using the green checkmark left hand to my answer? – mahal tertin Feb 03 '16 at 09:18