> On Dec 21, 2019, at 12:56, Gabriel Zachmann <z...@cs.uni-bremen.de> wrote:
> 
> 
> Thanks a lot!
> 
> Does it really watch subfolders, too?

The docs can answer this better I.

> 
> Also, it seems to me like it works only while the program is running.
> 
> I am mostly interested in changes that happen "behind the program's back",
> i.e., while it is *not* running.

If your code is not running what is looking for changes?
Are you looking to detect changes that happen in between launches of your app?  
If so you’d have to save state and compare that saved state to the dir contents 
each time the app is launched.  I’d just use a directory enumerator for this.  
Then you can use the dispatch stuff to monitor while running.

Sandor

> Does your code really handle that?
> 
> Best regards, Gabriel
> 
> 
>> I’ve used dispatch stuff.  I found this with a quick google… it should be 
>> close to what one would need to monitor a folder.
>> int fildes = open("/path/to/directory", O_RDONLY);
>> 
>> dispatch_queue_t queue = 
>> dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
>> dispatch_source_t source = 
>> dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fildes, 
>> DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE | DISPATCH_VNODE_EXTEND | 
>> DISPATCH_VNODE_RENAME | DISPATCH_VNODE_REVOKE, queue);
>> 
>> dispatch_source_set_event_handler(source, ^{
>> // ... handle changes
>> });
>> 
>> dispatch_source_set_cancel_handler(source, ^{
>> // ... handle cancel
>> });
>> 
>> dispatch_resume(source); // Start monitoring
>> 
>> // And sometime later
>> dispatch_source_cancel(source); // Stop monitoring
> 
_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to