Last active
December 19, 2015 11:29
-
-
Save edwardean/c85b60e42d6ab104e6a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dispatch_source_t cookitSourceWithFile(const char *cookieFileName) { | |
| int fd = open(cookieFileName, O_EVTONLY); | |
| if (fd == -1) { | |
| return NULL; | |
| } | |
| fcntl(fd, F_SETFL, O_NONBLOCK); | |
| dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fd,DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE | DISPATCH_VNODE_EXTEND | DISPATCH_VNODE_RENAME | DISPATCH_VNODE_REVOKE, DISPATCH_TARGET_QUEUE_DEFAULT); | |
| if (!source) { | |
| close(fd); | |
| return NULL; | |
| } | |
| dispatch_source_set_event_handler(source, ^{ | |
| unsigned long const type = dispatch_source_get_data(source); | |
| switch (type) { | |
| case DISPATCH_VNODE_WRITE: { | |
| NSLog(@"目录内容改变!!!"); | |
| break; | |
| } | |
| case DISPATCH_VNODE_RENAME: { | |
| NSLog(@"目录被重命名!!!"); | |
| break; | |
| } | |
| default: | |
| break; | |
| } | |
| }); | |
| dispatch_source_set_cancel_handler(source, ^{ | |
| close((int)dispatch_source_get_handle(source)); | |
| }); | |
| dispatch_resume(source); | |
| return source; | |
| } | |
| NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject]; | |
| NSString *cookieFile = [documentsDirectory stringByAppendingPathComponent:@"Cookies/"]; | |
| self.source = cookitSourceWithFile([cookieFile UTF8String]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment