http://stackoverflow.com/questions/12343833/cocoa-monitor-a-file-for-modifications/26304208#26304208
has some info on this. ___ Peter Hartmann ________ mailto:hphartm...@justmail.de Am 05.11.2014 um 07:50 schrieb Gerriet M. Denkmann <gerr...@mdenkmann.de>: > I want to monitor a file for changed content. > Polling is generally not a good idea, so I tried dispatch_source. > > But it does not work. > > Here the code: > > static NSString *const kTestPath = @"/tmp/a.test"; > > - (void)applicationDidFinishLaunching:(NSNotification *)aNotification > { > const char *filename = kTestPath.fileSystemRepresentation; > int fd = open(filename, O_RDONLY); > fcntl(fd, F_SETFL, O_NONBLOCK); > uintptr_t fD = (uintptr_t)fd; > dispatch_queue_t queue = > dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); > const uint64_t flags = DISPATCH_VNODE_WRITE | DISPATCH_VNODE_LINK; > dispatch_source_t my_source = > dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fD, flags, queue); > dispatch_source_set_event_handler(my_source, ^{ [self fileDidChange]; } > ); > dispatch_resume(my_source); > } > > - (void)fileDidChange > { > NSLog(@"%s",__FUNCTION__); // never seen > } > > - (IBAction)buttonClicked: sender > { > static NSUInteger seqq = 0; > seqq++; > > const char *stats_temp_file = "/tmp/a.temp"; > FILE *fp = fopen(stats_temp_file, "w"); > fprintf(fp, "%lu\n", seqq); > (void)fclose(fp); > > const char *filename = kTestPath.fileSystemRepresentation; > int a = rename(stats_temp_file, filename); > } > > What am I doing wrong? (Writing directly to kTestPath without rename() also > does not work). > > Gerriet. > > > _______________________________________________ > > 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/magnard%40web.de > > This email sent to magn...@web.de _______________________________________________ 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