site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> unsigned int InodeForFileDescriptor( int fd ) { struct stat sb; if ( fstat( fd, &sb ) == 0 ) return sb.st_ino; // fstat() returns 0 on success else return 0; } - (void) fileDeletedNotification:(NSNotification *)note; { NSString *path = [note object]; unsigned int inode = [kqueue inodeForPathInQueue:path]; [kqueue removePathFromQueue:path]; if ( inode ) { NSString *parentDirectory = [path stringByDeletingLastPathComponent]; NSArray *files = [[NSFileManager defaultManager] directoryContentsAtPath:parentDirectory]; NSEnumerator *e = [files objectEnumerator]; NSString *lastPathComponent; while ( lastPathComponent = [e nextObject] ) { BOOL isDirectory = NO; NSString *fullPath = [parentDirectory stringByAppendingPathComponent:lastPathComponent]; [[NSFileManager defaultManager] fileExistsAtPath:fullPath isDirectory:&isDirectory]; if ( isDirectory == NO ) // we're looking for a file { NSFileHandle *fh = [NSFileHandle fileHandleForReadingAtPath:fullPath]; int fd = [fh fileDescriptor]; if ( InodeForFileDescriptor( fd ) == inode ) { // hack to get file to actually delete unlink( [fullPath cString] ); break; } } } } [kqueue addPathToQueue:path]; // the file exists again by the time we get here [self fileWrittenToNotification:note]; // my file modified code }