| 210 | } |
| 211 | |
| 212 | void WatcherKqueue::removeFile( const std::string& name, bool emitEvents ) { |
| 213 | efDEBUG( "removeFile(): Trying to remove file: %s\n", name.c_str() ); |
| 214 | |
| 215 | // bsearch |
| 216 | KEvent target; |
| 217 | |
| 218 | // Create a temporary file info to search the kevent ( searching the directory ) |
| 219 | FileInfo tempEntry( name ); |
| 220 | |
| 221 | target.udata = &tempEntry; |
| 222 | |
| 223 | // Search the kevent |
| 224 | KEvent* ke = (KEvent*)bsearch( &target, &mChangeList[1], mChangeListCount, sizeof( KEvent ), |
| 225 | comparator ); |
| 226 | |
| 227 | // Trying to remove a non-existing file? |
| 228 | if ( !ke ) { |
| 229 | Errors::Log::createLastError( Errors::FileNotFound, name ); |
| 230 | efDEBUG( "File not removed\n" ); |
| 231 | return; |
| 232 | } |
| 233 | |
| 234 | efDEBUG( "File removed\n" ); |
| 235 | |
| 236 | // handle action |
| 237 | if ( emitEvents ) { |
| 238 | handleAction( name, Actions::Delete ); |
| 239 | } |
| 240 | |
| 241 | // Delete the user data ( FileInfo ) from the kevent closed |
| 242 | FileInfo* del = reinterpret_cast<FileInfo*>( ke->udata ); |
| 243 | |
| 244 | efSAFE_DELETE( del ); |
| 245 | |
| 246 | // close the file descriptor from the kevent |
| 247 | close( ke->ident ); |
| 248 | |
| 249 | mWatcher->removeFD(); |
| 250 | |
| 251 | memset( ke, 0, sizeof( KEvent ) ); |
| 252 | |
| 253 | // move end to current |
| 254 | memcpy( ke, &mChangeList[mChangeListCount], sizeof( KEvent ) ); |
| 255 | memset( &mChangeList[mChangeListCount], 0, sizeof( KEvent ) ); |
| 256 | --mChangeListCount; |
| 257 | } |
| 258 | |
| 259 | void WatcherKqueue::rescan() { |
| 260 | efDEBUG( "rescan(): Rescanning: %s\n", Directory.c_str() ); |