void FileWatcherOSX::update() { int nev = 0; struct kevent event; WatchMap::iterator iter = mWatches.begin(); WatchMap::iterator end = mWatches.end(); for(; iter != end; ++iter) { WatchStruct* watch = iter->second; while((nev = kevent(mDescriptor, (KEvent*)&(watch->mChangeList), watch->mChangeListCount + 1, &event, 1, &mTimeOut)) != 0) { if(nev == -1) perror("kevent"); else { EntryStruct* entry = 0; if((entry = (EntryStruct*)event.udata) != 0) { //fprintf(stderr, "File: %s -- ", (char*)entry->mFilename); if(event.fflags & NOTE_DELETE) { //fprintf(stderr, "File deleted\n"); //watch->handleAction(entry->mFilename, Action::Delete); watch->removeFile(entry->mFilename); } if(event.fflags & NOTE_EXTEND || event.fflags & NOTE_WRITE || event.fflags & NOTE_ATTRIB) { //fprintf(stderr, "modified\n"); //watch->rescan(); struct stat attrib; stat(entry->mFilename, &attrib); entry->mModifiedTime = attrib.st_mtime; watch->handleAction(entry->mFilename, Action::Modified); } } else { //fprintf(stderr, "Dir: %s -- rescanning\n", watch->mDirName.c_str()); watch->rescan(); } } } } }
void FileWatcherOSX::update() { int nev = 0; struct kevent event; WatchMap::iterator iter = mWatches.begin(); WatchMap::iterator end = mWatches.end(); for(; iter != end; ++iter) { WatchStruct* watch = iter->second; while((nev = kevent(mDescriptor, (KEvent*)&(watch->mChangeList), watch->mChangeListCount + 1, &event, 1, &mTimeOut)) != 0) { if(nev == -1) perror("kevent"); else if ( nev > 0 ) { EntryStruct* entry = 0; if((entry = (EntryStruct*)event.udata) != 0) { // the watchID of the entry doesn't match the watchID of the WatchStruct. // instead, find it in the map and return it here. watch = mWatches[ entry->mWatchID ]; if ( !watch ) { //fprintf( stderr, "Unable to find watchID: %u\n", (unsigned int)entry->mWatchID ); continue; } if ( event.filter == EVFILT_VNODE ) { //fprintf(stderr, "Watch: %u, %u, File: %s -- ", (unsigned int)watch->mWatchID, (unsigned int)entry->mWatchID, (char*)entry->mFilename); if(event.fflags & NOTE_DELETE) { //fprintf(stderr, "File deleted\n"); //watch->handleAction(entry->mFilename, FW::Actions::Delete); watch->removeFile(entry->mFilename); watch->rescan(); } if(event.fflags & NOTE_EXTEND || event.fflags & NOTE_WRITE || event.fflags & NOTE_ATTRIB) { //fprintf(stderr, "modified\n"); //watch->rescan(); struct stat attrib; stat(entry->mFilename, &attrib); entry->mModifiedTime = attrib.st_mtime; watch->handleAction(entry->mFilename, FW::Actions::Modified); } } } else { //fprintf(stderr, "Dir: %s -- rescanning\n", watch->mDirName.c_str()); watch->rescan(); } } } } }