Closed sebromero closed 10 years ago
I suggest to only open the filedescriptor in the startMonitoring method:
- (void)startMonitoring
{
@synchronized(self)
{
if (_source)
{
return;
}
_fileDescriptor = open([_URL.path fileSystemRepresentation], O_EVTONLY);
if (!_fileDescriptor) {
return;
}
// watch the file descriptor for writes
_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, _fileDescriptor, DISPATCH_VNODE_WRITE, _queue);
// call the passed block if the source is modified
dispatch_source_set_event_handler(_source, _block);
// close the file descriptor when the dispatch source is cancelled
dispatch_source_set_cancel_handler(_source, ^{
close(_fileDescriptor);
});
// at this point the dispatch source is paused, so start watching
dispatch_resume(_source);
}
}
Please send a pull request
Von meinem iPhone gesendet
Am 01.05.2014 um 13:59 schrieb Sebastian notifications@github.com:
I suggest to only open the filedescriptor in the startMonitoring method:
(void)startMonitoring { @synchronized(self) { if (_source) { return; }
_fileDescriptor = open([_URL.path fileSystemRepresentation], O_EVTONLY); if (!_fileDescriptor) { return; } // watch the file descriptor for writes _source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, _fileDescriptor, DISPATCH_VNODE_WRITE, _queue); // call the passed block if the source is modified dispatch_source_set_event_handler(_source, _block); // close the file descriptor when the dispatch source is cancelled dispatch_source_set_cancel_handler(_source, ^{ close(_fileDescriptor); }); // at this point the dispatch source is paused, so start watching dispatch_resume(_source);
} } — Reply to this email directly or view it on GitHub.
Merged the fix into develop, will release soon.
When i use start/stop the folder monitor more then once the app will crash because the file descriptor is closed when stopMonitoring is called. So when calling startMonitoring and stopMonitoring again the filedescriptor is invalid which will lead to a crash inside the cancel handler.