0

I have a plist file which is being monitored for changes using FSEvents API.

_fileStream = FSEventStreamCreate(NULL,
                                  &fsevents_apps_callback,
                                  &context,
                                  (__bridge CFArrayRef)[NSArray arrayWithObject:@"/"],
                                  kFSEventStreamEventIdSinceNow,
                                  (CFAbsoluteTime)0.2,
                                  kFSEventStreamCreateFlagFileEvents);

// start the stream on the main event loop
FSEventStreamScheduleWithRunLoop(_fileStream,
                                 CFRunLoopGetCurrent(),
                                 kCFRunLoopDefaultMode);
FSEventStreamStart(_fileStream);

I am using sudo defaults to write to plist. Sudo defaults /Library/Application Support/myApp/file.plist

In my callBack function , the event path is turning out to be /Library/Application Support/myApp/file.plist.52738

I am concerned with it being detecting as file.plist.2332(some random number) and not file.plist

Any Inputs why this behaviour is seen ?

If we use PlistBuddy to write it , it all looks fine and event path is /Library/Application Support/myApp/file.plist.

sac
  • 890
  • 6
  • 19
  • Why do you use sudo defaults to write? Can't you use NSUserDefaults and watch for changes like this: http://stackoverflow.com/questions/1141388/cocoa-notification-on-nsuserdefaults-value-change – mahal tertin Apr 16 '15 at 12:18

1 Answers1

0

This behavior could be seen because of this:

  • In OS X 10.9 and newer there is a special deamon doing all the defaults reading and writing. it's called cfprefsd and runs as root as well as the logged in users. It does all of the caching and flushing and coordination with persistency on disk.
mahal tertin
  • 3,239
  • 24
  • 41