The way to handle adding a new directory is to basically tear down the stream and recreate it adding the new directory. You won't lose any events while your recreating the stream due to the caching done behind the scenes.
When I stop a stream, I do the following: -(void) streamDestroy { FSEventStreamStop(eventStream); // This will prevent your event handler from being called Snip... // do anything else you need to do. NSRunLoop * mainLoop = [NSRunLoop mainRunLoop]; // remove it from the run loop and FSEventStreamUnscheduleFromRunLoop(eventStream, [mainLoop getCFRunLoop], kCFRunLoopDefaultMode); FSEventStreamInvalidate(eventStream); // Tear down the stream. FSEventStreamRelease(eventStream); eventStream = NULL; } Once the stream is destroyed, just recreate the stream with the new directories you are interested in listening to. I am able to add and remove directories at will. HTH, Tony Romano On 6/16/11 3:33 AM, "Ajay Sabhaney" <co...@mothercreative.com> wrote: >Hello, > >I have setup an FSEventStream so that I can monitor a directory for file >changes. If the root directory that is being watched is moved/renamed, I >want to be able to keep monitoring the directory. I am able to get the >new path of the root directory, however I am unsure of how to monitor the >new path. If I try to stop monitoring the watched directory (so I can >subsequently monitor the new root directory path), the following error >message is logged to my console: > >(CarbonCore.framework) process_dir_events: watch_path: error trying to >add kqueue for fd 5 (/Users/path/to/orig/dir; Bad file descriptor) >(CarbonCore.framework) process_dir_events: watch_path: error removing fd >6 from kqueue (Bad file descriptor) >(CarbonCore.framework) process_dir_events: watch_all_parents: error >trying to add kqueue for fd 6 (/Users/path/to/orig; Bad file descriptor) >(CarbonCore.framework) process_dir_events: watch_all_parents: error >trying to add kqueue for fd 7 (/Users/path/to; Bad file descriptor) >(CarbonCore.framework) process_dir_events: watch_all_parents: error >trying to add kqueue for fd 8 (/Users/path; Bad file descriptor) >(CarbonCore.framework) process_dir_events: watch_all_parents: error >trying to add kqueue for fd 9 (/Users; Bad file descriptor) > >I'd appreciate if someone can suggest a way to monitor the new directory >path (and stop monitoring the original location) when receiving a >kFSEventStreamEventFlagRootChanged flag. If invalidating and stopping >the stream (then restarting it) is the way to go, perhaps someone could >shed some light as to why I'm receiving the error mentioned above. > >A similar question has been asked (but not yet solved) in the following >thread: >http://lists.apple.com/archives/filesystem-dev/2010/May/msg00007.html > >Ajay >_______________________________________________ > >Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > >Please do not post admin requests or moderator comments to the list. >Contact the moderators at cocoa-dev-admins(at)lists.apple.com > >Help/Unsubscribe/Update your Subscription: >http://lists.apple.com/mailman/options/cocoa-dev/tonyrom%40hotmail.com > >This email sent to tony...@hotmail.com > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com