diff options
author | Naios <naios-dev@live.de> | 2017-02-27 15:49:04 +0100 |
---|---|---|
committer | Naios <naios-dev@live.de> | 2017-02-27 22:52:48 +0100 |
commit | 22fede37746287fa0b7fd0e7113265d538e4fb41 (patch) | |
tree | 90e1d6af1a362859bf2d6ac2940ecd96aeeee5f6 | |
parent | 7de5befbc39cd6bf45166fd2c5d0532065f7e99e (diff) |
Dep: Update efsw to version 1.0.0
-rw-r--r-- | dep/PackageList.txt | 2 | ||||
-rw-r--r-- | dep/efsw/.hg_archival.txt | 7 | ||||
-rw-r--r-- | dep/efsw/src/efsw/DirectorySnapshot.cpp | 2 | ||||
-rw-r--r-- | dep/efsw/src/efsw/FileInfo.cpp | 5 | ||||
-rw-r--r-- | dep/efsw/src/efsw/FileWatcherFSEvents.cpp | 36 | ||||
-rw-r--r-- | dep/efsw/src/efsw/FileWatcherGeneric.cpp | 32 | ||||
-rw-r--r-- | dep/efsw/src/efsw/FileWatcherInotify.cpp | 44 | ||||
-rw-r--r-- | dep/efsw/src/efsw/FileWatcherKqueue.cpp | 40 | ||||
-rw-r--r-- | dep/efsw/src/efsw/FileWatcherWin32.cpp | 182 | ||||
-rw-r--r-- | dep/efsw/src/efsw/FileWatcherWin32.hpp | 21 | ||||
-rw-r--r-- | dep/efsw/src/efsw/Lock.hpp | 27 | ||||
-rw-r--r-- | dep/efsw/src/efsw/WatcherFSEvents.cpp | 12 | ||||
-rw-r--r-- | dep/efsw/src/efsw/WatcherWin32.cpp | 8 | ||||
-rw-r--r-- | dep/efsw/src/efsw/base.hpp | 7 | ||||
-rw-r--r-- | dep/efsw/src/efsw/platform/win/ThreadImpl.cpp | 8 | ||||
-rw-r--r-- | dep/efsw/src/efsw/platform/win/ThreadImpl.hpp | 2 |
16 files changed, 238 insertions, 197 deletions
diff --git a/dep/PackageList.txt b/dep/PackageList.txt index ff5f018cf29..6ffa9c8a822 100644 --- a/dep/PackageList.txt +++ b/dep/PackageList.txt @@ -18,7 +18,7 @@ cppformat (type safe format library) efws (Entropia File System Watcher - crossplatform file system watcher) https://bitbucket.org/SpartanJ/efsw - ff0b69daeca1edf7785a8a580518e462be5a6f3d + Version: 1.0.0 e4ead877688b6cd736a2326fb10507fa01c26f8f G3D (a commercial-grade C++ 3D engine available as Open Source (BSD License) http://g3d.sourceforge.net/ diff --git a/dep/efsw/.hg_archival.txt b/dep/efsw/.hg_archival.txt index 19565afb668..9fe34b1c56e 100644 --- a/dep/efsw/.hg_archival.txt +++ b/dep/efsw/.hg_archival.txt @@ -1,5 +1,6 @@ repo: 78c2ea8c48b213ee0078d6326a1dd719d0844764 -node: ff0b69daeca1edf7785a8a580518e462be5a6f3d +node: e4ead877688b6cd736a2326fb10507fa01c26f8f branch: default -latesttag: null -latesttagdistance: 144 +latesttag: 1.0.0 +latesttagdistance: 1 +changessincelatesttag: 1 diff --git a/dep/efsw/src/efsw/DirectorySnapshot.cpp b/dep/efsw/src/efsw/DirectorySnapshot.cpp index c0ef747548a..e0680483e6b 100644 --- a/dep/efsw/src/efsw/DirectorySnapshot.cpp +++ b/dep/efsw/src/efsw/DirectorySnapshot.cpp @@ -44,6 +44,8 @@ void DirectorySnapshot::deleteAll( DirectorySnapshotDiff& Diff ) Diff.FilesDeleted.push_back( fi ); } } + + Files.clear(); } void DirectorySnapshot::setDirectoryInfo( std::string directory ) diff --git a/dep/efsw/src/efsw/FileInfo.cpp b/dep/efsw/src/efsw/FileInfo.cpp index 7003afc2a15..7b405949698 100644 --- a/dep/efsw/src/efsw/FileInfo.cpp +++ b/dep/efsw/src/efsw/FileInfo.cpp @@ -192,7 +192,12 @@ bool FileInfo::isRegularFile() bool FileInfo::isReadable() { +#if EFSW_PLATFORM != EFSW_PLATFORM_WIN32 + static bool isRoot = getuid() == 0; + return isRoot || 0 != S_ISRDBL(Permissions); +#else return 0 != S_ISRDBL(Permissions); +#endif } bool FileInfo::isLink() diff --git a/dep/efsw/src/efsw/FileWatcherFSEvents.cpp b/dep/efsw/src/efsw/FileWatcherFSEvents.cpp index 40156674132..524b6f1bb3b 100644 --- a/dep/efsw/src/efsw/FileWatcherFSEvents.cpp +++ b/dep/efsw/src/efsw/FileWatcherFSEvents.cpp @@ -3,6 +3,7 @@ #include <efsw/System.hpp> #include <efsw/Debug.hpp> #include <efsw/String.hpp> +#include <efsw/Lock.hpp> #if EFSW_PLATFORM == EFSW_PLATFORM_FSEVENTS @@ -14,11 +15,11 @@ namespace efsw int getOSXReleaseNumber() { static int osxR = -1; - + if ( -1 == osxR ) { struct utsname os; - + if ( -1 != uname( &os ) ) { std::string release( os.release ); @@ -83,6 +84,10 @@ FileWatcherFSEvents::FileWatcherFSEvents( FileWatcher * parent ) : FileWatcherFSEvents::~FileWatcherFSEvents() { + mInitOK = false; + + efSAFE_DELETE( mThread ); + WatchMap::iterator iter = mWatches.begin(); for( ; iter != mWatches.end(); ++iter ) @@ -93,15 +98,6 @@ FileWatcherFSEvents::~FileWatcherFSEvents() } mWatches.clear(); - - mInitOK = false; - - if ( NULL != mRunLoopRef ) - { - CFRunLoopStop( mRunLoopRef ); - } - - efSAFE_DELETE( mThread ); } WatchID FileWatcherFSEvents::addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive ) @@ -165,16 +161,15 @@ WatchID FileWatcherFSEvents::addWatch( const std::string& directory, FileWatchLi pWatch->init(); - mWatchesLock.lock(); + Lock lock( mWatchesLock ); mWatches.insert(std::make_pair(mLastWatchID, pWatch)); - mWatchesLock.unlock(); return pWatch->ID; } void FileWatcherFSEvents::removeWatch(const std::string& directory) { - mWatchesLock.lock(); + Lock lock( mWatchesLock ); WatchMap::iterator iter = mWatches.begin(); @@ -186,13 +181,11 @@ void FileWatcherFSEvents::removeWatch(const std::string& directory) return; } } - - mWatchesLock.unlock(); } void FileWatcherFSEvents::removeWatch(WatchID watchid) { - mWatchesLock.lock(); + Lock lock( mWatchesLock ); WatchMap::iterator iter = mWatches.find( watchid ); @@ -206,8 +199,6 @@ void FileWatcherFSEvents::removeWatch(WatchID watchid) efDEBUG( "Removed watch %s\n", watch->Directory.c_str() ); efSAFE_DELETE( watch ); - - mWatchesLock.unlock(); } void FileWatcherFSEvents::watch() @@ -237,6 +228,9 @@ void FileWatcherFSEvents::run() CFRunLoopRunInMode( kCFRunLoopDefaultMode, 0.5, kCFRunLoopRunTimedOut ); } + + CFRunLoopStop( mRunLoopRef ); + mRunLoopRef = NULL; } void FileWatcherFSEvents::handleAction(Watcher* watch, const std::string& filename, unsigned long action, std::string oldFilename) @@ -248,15 +242,13 @@ std::list<std::string> FileWatcherFSEvents::directories() { std::list<std::string> dirs; - mWatchesLock.lock(); + Lock lock( mWatchesLock ); for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) { dirs.push_back( std::string( it->second->Directory ) ); } - mWatchesLock.unlock(); - return dirs; } diff --git a/dep/efsw/src/efsw/FileWatcherGeneric.cpp b/dep/efsw/src/efsw/FileWatcherGeneric.cpp index 1534b6a9279..6a37c025492 100644 --- a/dep/efsw/src/efsw/FileWatcherGeneric.cpp +++ b/dep/efsw/src/efsw/FileWatcherGeneric.cpp @@ -1,6 +1,7 @@ #include <efsw/FileWatcherGeneric.hpp> #include <efsw/FileSystem.hpp> #include <efsw/System.hpp> +#include <efsw/Lock.hpp> namespace efsw { @@ -18,8 +19,6 @@ FileWatcherGeneric::~FileWatcherGeneric() { mInitOK = false; - mThread->wait(); - efSAFE_DELETE( mThread ); /// Delete the watches @@ -75,9 +74,8 @@ WatchID FileWatcherGeneric::addWatch(const std::string& directory, FileWatchList WatcherGeneric * pWatch = new WatcherGeneric( mLastWatchID, dir, watcher, this, recursive ); - mWatchesLock.lock(); + Lock lock( mWatchesLock ); mWatches.push_back(pWatch); - mWatchesLock.unlock(); return pWatch->ID; } @@ -92,14 +90,12 @@ void FileWatcherGeneric::removeWatch( const std::string& directory ) { WatcherGeneric * watch = (*it); - mWatchesLock.lock(); + Lock lock( mWatchesLock ); mWatches.erase( it ); efSAFE_DELETE( watch ) ; - mWatchesLock.unlock(); - return; } } @@ -115,14 +111,12 @@ void FileWatcherGeneric::removeWatch(WatchID watchid) { WatcherGeneric * watch = (*it); - mWatchesLock.lock(); + Lock lock( mWatchesLock ); mWatches.erase( it ); efSAFE_DELETE( watch ) ; - mWatchesLock.unlock(); - return; } } @@ -141,17 +135,17 @@ void FileWatcherGeneric::run() { do { - mWatchesLock.lock(); + { + Lock lock( mWatchesLock); - WatchList::iterator it = mWatches.begin(); + WatchList::iterator it = mWatches.begin(); - for ( ; it != mWatches.end(); it++ ) - { - (*it)->watch(); + for ( ; it != mWatches.end(); it++ ) + { + ( *it )->watch(); + } } - mWatchesLock.unlock(); - if ( mInitOK ) System::sleep( 1000 ); } while ( mInitOK ); } @@ -165,7 +159,7 @@ std::list<std::string> FileWatcherGeneric::directories() { std::list<std::string> dirs; - mWatchesLock.lock(); + Lock lock( mWatchesLock ); WatchList::iterator it = mWatches.begin(); @@ -174,8 +168,6 @@ std::list<std::string> FileWatcherGeneric::directories() dirs.push_back( (*it)->Directory ); } - mWatchesLock.unlock(); - return dirs; } diff --git a/dep/efsw/src/efsw/FileWatcherInotify.cpp b/dep/efsw/src/efsw/FileWatcherInotify.cpp index 19c20761663..6c10271994a 100644 --- a/dep/efsw/src/efsw/FileWatcherInotify.cpp +++ b/dep/efsw/src/efsw/FileWatcherInotify.cpp @@ -18,6 +18,7 @@ #include <efsw/FileSystem.hpp> #include <efsw/System.hpp> #include <efsw/Debug.hpp> +#include <efsw/Lock.hpp> #define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024) @@ -145,9 +146,10 @@ WatchID FileWatcherInotify::addWatch( const std::string& directory, FileWatchLis pWatch->Recursive = recursive; pWatch->Parent = parent; - mWatchesLock.lock(); - mWatches.insert(std::make_pair(wd, pWatch)); - mWatchesLock.unlock(); + { + Lock lock( mWatchesLock ); + mWatches.insert(std::make_pair(wd, pWatch)); + } if ( NULL == pWatch->Parent ) { @@ -228,7 +230,7 @@ void FileWatcherInotify::removeWatchLocked(WatchID watchid) void FileWatcherInotify::removeWatch(const std::string& directory) { - mWatchesLock.lock(); + Lock lock( mWatchesLock ); WatchMap::iterator iter = mWatches.begin(); @@ -285,26 +287,20 @@ void FileWatcherInotify::removeWatch(const std::string& directory) break; } } - - mWatchesLock.unlock(); } void FileWatcherInotify::removeWatch( WatchID watchid ) { - mWatchesLock.lock(); + Lock lock( mWatchesLock ); WatchMap::iterator iter = mWatches.find( watchid ); if( iter == mWatches.end() ) { - mWatchesLock.unlock(); - return; } removeWatchLocked( watchid ); - - mWatchesLock.unlock(); } void FileWatcherInotify::watch() @@ -343,23 +339,23 @@ void FileWatcherInotify::run() { struct inotify_event *pevent = (struct inotify_event *)&buff[i]; - mWatchesLock.lock(); - - wit = mWatches.find( pevent->wd ); - - if ( wit != mWatches.end() ) { - handleAction(wit->second, pevent->name, pevent->mask); + Lock lock( mWatchesLock ); + + wit = mWatches.find( pevent->wd ); - /// Keep track of the IN_MOVED_FROM events to known if the IN_MOVED_TO event is also fired - if ( !wit->second->OldFileName.empty() ) + if ( wit != mWatches.end() ) { - movedOutsideWatches.push_back( wit->second ); + handleAction(wit->second, pevent->name, pevent->mask); + + /// Keep track of the IN_MOVED_FROM events to known if the IN_MOVED_TO event is also fired + if ( !wit->second->OldFileName.empty() ) + { + movedOutsideWatches.push_back( wit->second ); + } } } - mWatchesLock.unlock(); - i += sizeof(struct inotify_event) + pevent->len; } @@ -496,7 +492,7 @@ std::list<std::string> FileWatcherInotify::directories() { std::list<std::string> dirs; - mWatchesLock.lock(); + Lock lock( mWatchesLock ); WatchMap::iterator it = mRealWatches.begin(); @@ -505,8 +501,6 @@ std::list<std::string> FileWatcherInotify::directories() dirs.push_back( it->second->Directory ); } - mWatchesLock.unlock(); - return dirs; } diff --git a/dep/efsw/src/efsw/FileWatcherKqueue.cpp b/dep/efsw/src/efsw/FileWatcherKqueue.cpp index 600fd085b35..d8a76b8995b 100644 --- a/dep/efsw/src/efsw/FileWatcherKqueue.cpp +++ b/dep/efsw/src/efsw/FileWatcherKqueue.cpp @@ -15,6 +15,7 @@ #include <efsw/System.hpp> #include <efsw/Debug.hpp> #include <efsw/WatcherGeneric.hpp> +#include <efsw/Lock.hpp> namespace efsw { @@ -44,8 +45,6 @@ FileWatcherKqueue::~FileWatcherKqueue() mInitOK = false; - mThread->wait(); - efSAFE_DELETE( mThread ); } @@ -98,9 +97,10 @@ WatchID FileWatcherKqueue::addWatch(const std::string& directory, FileWatchListe WatcherKqueue * watch = new WatcherKqueue( ++mLastWatchID, dir, watcher, recursive, this ); - mWatchesLock.lock(); - mWatches.insert(std::make_pair(mLastWatchID, watch)); - mWatchesLock.unlock(); + { + Lock lock( mWatchesLock ); + mWatches.insert(std::make_pair(mLastWatchID, watch)); + } watch->addAll(); @@ -120,9 +120,8 @@ WatchID FileWatcherKqueue::addWatch(const std::string& directory, FileWatchListe { WatcherGeneric * watch = new WatcherGeneric( ++mLastWatchID, dir, watcher, this, recursive ); - mWatchesLock.lock(); + Lock lock( mWatchesLock ); mWatches.insert(std::make_pair(mLastWatchID, watch)); - mWatchesLock.unlock(); } else { @@ -142,9 +141,8 @@ WatchID FileWatcherKqueue::addWatch(const std::string& directory, FileWatchListe WatcherGeneric * watch = new WatcherGeneric( ++mLastWatchID, dir, watcher, this, recursive ); - mWatchesLock.lock(); + Lock lock( mWatchesLock ); mWatches.insert(std::make_pair(mLastWatchID, watch)); - mWatchesLock.unlock(); } return mLastWatchID; @@ -152,7 +150,7 @@ WatchID FileWatcherKqueue::addWatch(const std::string& directory, FileWatchListe void FileWatcherKqueue::removeWatch(const std::string& directory) { - mWatchesLock.lock(); + Lock lock( mWatchesLock ); WatchMap::iterator iter = mWatches.begin(); @@ -164,13 +162,11 @@ void FileWatcherKqueue::removeWatch(const std::string& directory) return; } } - - mWatchesLock.unlock(); } void FileWatcherKqueue::removeWatch(WatchID watchid) { - mWatchesLock.lock(); + Lock lock( mWatchesLock ); WatchMap::iterator iter = mWatches.find(watchid); @@ -182,8 +178,6 @@ void FileWatcherKqueue::removeWatch(WatchID watchid) mWatches.erase(iter); efSAFE_DELETE( watch ); - - mWatchesLock.unlock(); } bool FileWatcherKqueue::isAddingWatcher() const @@ -204,14 +198,14 @@ void FileWatcherKqueue::run() { do { - mWatchesLock.lock(); - - for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); ++it ) { - it->second->watch(); - } + Lock lock( mWatchesLock ); - mWatchesLock.unlock(); + for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); ++it ) + { + it->second->watch(); + } + } System::sleep( 500 ); } while( mInitOK ); @@ -225,7 +219,7 @@ std::list<std::string> FileWatcherKqueue::directories() { std::list<std::string> dirs; - mWatchesLock.lock(); + Lock lock( mWatchesLock ); WatchMap::iterator it = mWatches.begin(); @@ -234,8 +228,6 @@ std::list<std::string> FileWatcherKqueue::directories() dirs.push_back( it->second->Directory ); } - mWatchesLock.unlock(); - return dirs; } diff --git a/dep/efsw/src/efsw/FileWatcherWin32.cpp b/dep/efsw/src/efsw/FileWatcherWin32.cpp index fe78dd122cf..4e85fc3dd00 100644 --- a/dep/efsw/src/efsw/FileWatcherWin32.cpp +++ b/dep/efsw/src/efsw/FileWatcherWin32.cpp @@ -2,6 +2,7 @@ #include <efsw/FileSystem.hpp> #include <efsw/System.hpp> #include <efsw/String.hpp> +#include <efsw/Lock.hpp> #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 @@ -18,23 +19,9 @@ FileWatcherWin32::FileWatcherWin32( FileWatcher * parent ) : FileWatcherWin32::~FileWatcherWin32() { - WatchVector::iterator iter = mWatches.begin(); - - mWatchesLock.lock(); - - for(; iter != mWatches.end(); ++iter) - { - DestroyWatch((*iter)); - } - - mHandles.clear(); - mWatches.clear(); - mInitOK = false; - - mWatchesLock.unlock(); - efSAFE_DELETE( mThread ); + removeAllWatches(); } WatchID FileWatcherWin32::addWatch(const std::string& directory, FileWatchListener* watcher, bool recursive) @@ -54,9 +41,14 @@ WatchID FileWatcherWin32::addWatch(const std::string& directory, FileWatchListen FileSystem::dirAddSlashAtEnd( dir ); - WatchID watchid = ++mLastWatchID; + Lock lock( mWatchesLock ); + + if ( pathInWatches( dir ) ) + { + return Errors::Log::createLastError( Errors::FileRepeated, dir ); + } - mWatchesLock.lock(); + WatchID watchid = ++mLastWatchID; WatcherStructWin32 * watch = CreateWatch( String::fromUtf8( dir ).toWideString().c_str(), recursive, FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_LAST_WRITE | @@ -70,11 +62,6 @@ WatchID FileWatcherWin32::addWatch(const std::string& directory, FileWatchListen return Errors::Log::createLastError( Errors::FileNotFound, dir ); } - if ( pathInWatches( dir ) ) - { - return Errors::Log::createLastError( Errors::FileRepeated, dir ); - } - // Add the handle to the handles vector watch->Watch->ID = watchid; watch->Watch->Watch = this; @@ -82,67 +69,81 @@ WatchID FileWatcherWin32::addWatch(const std::string& directory, FileWatchListen watch->Watch->DirName = new char[dir.length()+1]; strcpy(watch->Watch->DirName, dir.c_str()); - mHandles.push_back( watch->Watch->DirHandle ); - mWatches.push_back( watch ); - mWatchesLock.unlock(); + mWatchesNew.insert( watch ); + mWatches.insert( watch ); return watchid; } void FileWatcherWin32::removeWatch(const std::string& directory) { - mWatchesLock.lock(); + Lock lock( mWatchesLock ); - WatchVector::iterator iter = mWatches.begin(); + Watches::iterator iter = mWatches.begin(); for(; iter != mWatches.end(); ++iter) { if(directory == (*iter)->Watch->DirName) { - removeWatch((*iter)->Watch->ID); - return; + removeWatch(*iter); + break; } } - - mWatchesLock.unlock(); } void FileWatcherWin32::removeWatch(WatchID watchid) { - mWatchesLock.lock(); - - WatchVector::iterator iter = mWatches.begin(); + Lock lock( mWatchesLock ); - WatcherStructWin32* watch = NULL; + Watches::iterator iter = mWatches.begin(); for(; iter != mWatches.end(); ++iter) { // Find the watch ID if ( (*iter)->Watch->ID == watchid ) { - watch = (*iter); + removeWatch(*iter); + return; + } + } +} - mWatches.erase( iter ); +void FileWatcherWin32::removeWatch(WatcherStructWin32* watch) +{ + mWatchesRemoved.insert(watch); - // Remove handle from the handle vector - HandleVector::iterator it = mHandles.begin(); + if( NULL == mThread ) + { + removeWatches(); + } +} - for ( ; it != mHandles.end(); it++ ) - { - if ( watch->Watch->DirHandle == (*it) ) - { - mHandles.erase( it ); - break; - } - } +void FileWatcherWin32::removeWatches() +{ + Lock lock( mWatchesLock ); - DestroyWatch(watch); + Watches::iterator remWatchIter = mWatchesRemoved.begin(); - break; + for( ; remWatchIter != mWatchesRemoved.end(); ++remWatchIter ) + { + Watches::iterator iter = mWatches.find(*remWatchIter); + + if( iter != mWatches.end() ) + { + DestroyWatch(*iter); + + mWatches.erase( iter ); + } + + iter = mWatchesNew.find(*remWatchIter); + + if( iter != mWatchesNew.end() ) + { + mWatchesNew.erase( iter ); } } - mWatchesLock.unlock(); + mWatchesRemoved.clear(); } void FileWatcherWin32::watch() @@ -154,45 +155,47 @@ void FileWatcherWin32::watch() } } -void FileWatcherWin32::run() +void FileWatcherWin32::removeAllWatches() { - if ( mHandles.empty() ) + Lock lock( mWatchesLock ); + + Watches::iterator iter = mWatches.begin(); + + for( ; iter != mWatches.end(); ++iter ) { - return; + DestroyWatch((*iter)); } + mWatches.clear(); + mWatchesRemoved.clear(); + mWatchesNew.clear(); +} + +void FileWatcherWin32::run() +{ do { - if ( !mHandles.empty() ) + if ( !mWatches.empty() ) { - mWatchesLock.lock(); - - for ( std::size_t i = 0; i < mWatches.size(); i++ ) { - WatcherStructWin32 * watch = mWatches[ i ]; - - // If the overlapped struct was cancelled ( because the creator thread doesn't exists anymore ), - // we recreate the overlapped in the current thread and refresh the watch - if ( /*STATUS_CANCELED*/0xC0000120 == watch->Overlapped.Internal ) - { - watch->Overlapped = OVERLAPPED(); - RefreshWatch(watch); - } + Lock lock( mWatchesLock ); - // First ensure that the handle is the same, this means that the watch was not removed. - if ( HasOverlappedIoCompleted( &watch->Overlapped ) && mHandles[ i ] == watch->Watch->DirHandle ) + for( Watches::iterator iter = mWatches.begin() ; iter != mWatches.end(); ++iter ) { - DWORD bytes; + WatcherStructWin32 * watch = *iter; - if ( GetOverlappedResult( watch->Watch->DirHandle, &watch->Overlapped, &bytes, FALSE ) ) + if ( HasOverlappedIoCompleted( &watch->Overlapped ) ) { - WatchCallback( ERROR_SUCCESS, bytes, &watch->Overlapped ); + DWORD bytes; + + if ( GetOverlappedResult( watch->Watch->DirHandle, &watch->Overlapped, &bytes, FALSE ) ) + { + WatchCallback( ERROR_SUCCESS, bytes, &watch->Overlapped ); + } } } } - mWatchesLock.unlock(); - if ( mInitOK ) { System::sleep( 10 ); @@ -203,7 +206,18 @@ void FileWatcherWin32::run() // Wait for a new handle to be added System::sleep( 10 ); } + + removeWatches(); + + for ( Watches::iterator it = mWatchesNew.begin(); it != mWatchesNew.end(); it++ ) + { + RefreshWatch(*it); + } + + mWatchesNew.clear(); } while ( mInitOK ); + + removeAllWatches(); } void FileWatcherWin32::handleAction(Watcher* watch, const std::string& filename, unsigned long action, std::string oldFilename) @@ -232,7 +246,7 @@ void FileWatcherWin32::handleAction(Watcher* watch, const std::string& filename, FileSystem::dirAddSlashAtEnd( opath ); FileSystem::dirAddSlashAtEnd( fpath ); - for ( WatchVector::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) + for ( Watches::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) { if ( (*it)->Watch->Directory == opath ) { @@ -254,28 +268,36 @@ void FileWatcherWin32::handleAction(Watcher* watch, const std::string& filename, break; }; - watch->Listener->handleFileAction(watch->ID, static_cast<WatcherWin32*>( watch )->DirName, filename, fwAction); + std::string folderPath( static_cast<WatcherWin32*>( watch )->DirName ); + std::string realFilename = filename; + std::size_t sepPos = filename.find_last_of("/\\"); + + if ( sepPos != std::string::npos ) + { + folderPath += filename.substr( 0, sepPos ); + realFilename = filename.substr( sepPos + 1 ); + } + + watch->Listener->handleFileAction(watch->ID, folderPath, realFilename, fwAction); } std::list<std::string> FileWatcherWin32::directories() { std::list<std::string> dirs; - mWatchesLock.lock(); + Lock lock( mWatchesLock ); - for ( WatchVector::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) + for ( Watches::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) { dirs.push_back( std::string( (*it)->Watch->DirName ) ); } - mWatchesLock.unlock(); - return dirs; } bool FileWatcherWin32::pathInWatches( const std::string& path ) { - for ( WatchVector::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) + for ( Watches::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) { if ( (*it)->Watch->DirName == path ) { diff --git a/dep/efsw/src/efsw/FileWatcherWin32.hpp b/dep/efsw/src/efsw/FileWatcherWin32.hpp index 505cd772b82..983ee1853d0 100644 --- a/dep/efsw/src/efsw/FileWatcherWin32.hpp +++ b/dep/efsw/src/efsw/FileWatcherWin32.hpp @@ -6,7 +6,7 @@ #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 #include <efsw/WatcherWin32.hpp> -#include <vector> +#include <set> #include <map> namespace efsw @@ -18,8 +18,7 @@ class FileWatcherWin32 : public FileWatcherImpl { public: /// type for a map from WatchID to WatcherWin32 pointer - typedef std::vector<WatcherStructWin32*> WatchVector; - typedef std::vector<HANDLE> HandleVector; + typedef std::set<WatcherStructWin32*> Watches; FileWatcherWin32( FileWatcher * parent ); @@ -44,11 +43,9 @@ class FileWatcherWin32 : public FileWatcherImpl /// @return Returns a list of the directories that are being watched std::list<std::string> directories(); protected: - /// Vector of WatcherWin32 pointers - WatchVector mWatches; - - /// Keeps an updated handles vector - HandleVector mHandles; + Watches mWatches; + Watches mWatchesRemoved; + Watches mWatchesNew; /// The last watchid WatchID mLastWatchID; @@ -58,6 +55,14 @@ class FileWatcherWin32 : public FileWatcherImpl Mutex mWatchesLock; bool pathInWatches( const std::string& path ); + + /// Remove all directory watches. + void removeAllWatches(); + + /// Remove needed directory watches. + void removeWatches(); + + void removeWatch(WatcherStructWin32* watch); private: void run(); }; diff --git a/dep/efsw/src/efsw/Lock.hpp b/dep/efsw/src/efsw/Lock.hpp new file mode 100644 index 00000000000..5dbf11e39ce --- /dev/null +++ b/dep/efsw/src/efsw/Lock.hpp @@ -0,0 +1,27 @@ +#ifndef EFSW_LOCK_HPP +#define EFSW_LOCK_HPP + +#include <efsw/Mutex.hpp> + +namespace efsw { + +/** Simple mutex class */ +class Lock { + public: + explicit Lock( Mutex& mutex ) : + mMutex( mutex ) + { + mMutex.lock(); + } + + ~Lock() + { + mMutex.unlock(); + } + private: + Mutex& mMutex; +}; + +} + +#endif diff --git a/dep/efsw/src/efsw/WatcherFSEvents.cpp b/dep/efsw/src/efsw/WatcherFSEvents.cpp index 3a9700c77ec..a13a743b01e 100644 --- a/dep/efsw/src/efsw/WatcherFSEvents.cpp +++ b/dep/efsw/src/efsw/WatcherFSEvents.cpp @@ -27,14 +27,14 @@ WatcherFSEvents::WatcherFSEvents( WatchID id, std::string directory, FileWatchLi WatcherFSEvents::~WatcherFSEvents() { - if ( initializedAsync ) - { - FSEventStreamStop( FSStream ); - FSEventStreamInvalidate( FSStream ); - } - if ( NULL != FSStream ) { + if ( initializedAsync ) + { + FSEventStreamStop( FSStream ); + } + + FSEventStreamInvalidate( FSStream ); FSEventStreamRelease( FSStream ); } diff --git a/dep/efsw/src/efsw/WatcherWin32.cpp b/dep/efsw/src/efsw/WatcherWin32.cpp index 01d7b0fcd99..4d2dc7e064f 100644 --- a/dep/efsw/src/efsw/WatcherWin32.cpp +++ b/dep/efsw/src/efsw/WatcherWin32.cpp @@ -87,15 +87,9 @@ void DestroyWatch(WatcherStructWin32* pWatch) tWatch->StopNow = true; - CancelIo(tWatch->DirHandle); + CancelIoEx(tWatch->DirHandle, &pWatch->Overlapped); RefreshWatch(pWatch); - - if (!HasOverlappedIoCompleted(&pWatch->Overlapped)) - { - SleepEx(5, TRUE); - } - CloseHandle(pWatch->Overlapped.hEvent); CloseHandle(pWatch->Watch->DirHandle); efSAFE_DELETE_ARRAY( pWatch->Watch->DirName ); diff --git a/dep/efsw/src/efsw/base.hpp b/dep/efsw/src/efsw/base.hpp index 26108c76985..b5a9687dc74 100644 --- a/dep/efsw/src/efsw/base.hpp +++ b/dep/efsw/src/efsw/base.hpp @@ -38,7 +38,12 @@ typedef SOPHIST_uint64 Uint64; #if ( defined( _MSCVER ) || defined( _MSC_VER ) ) #define EFSW_COMPILER_MSVC #endif - + + /// Force windows target version above or equal to Windows Server 2008 or Windows Vista + #if _WIN32_WINNT < 0x600 + #undef _WIN32_WINNT + #define _WIN32_WINNT 0x600 + #endif #elif defined( __FreeBSD__ ) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined( __DragonFly__ ) #define EFSW_OS EFSW_OS_BSD #define EFSW_PLATFORM EFSW_PLATFORM_KQUEUE diff --git a/dep/efsw/src/efsw/platform/win/ThreadImpl.cpp b/dep/efsw/src/efsw/platform/win/ThreadImpl.cpp index 2fa30f30060..48c9456adab 100644 --- a/dep/efsw/src/efsw/platform/win/ThreadImpl.cpp +++ b/dep/efsw/src/efsw/platform/win/ThreadImpl.cpp @@ -18,6 +18,14 @@ ThreadImpl::ThreadImpl( Thread *owner ) } } +ThreadImpl::~ThreadImpl() +{ + if ( mThread ) + { + CloseHandle( mThread ); + } +} + void ThreadImpl::wait() { // Wait for the thread to finish, no timeout diff --git a/dep/efsw/src/efsw/platform/win/ThreadImpl.hpp b/dep/efsw/src/efsw/platform/win/ThreadImpl.hpp index 506c659c675..45e4505897a 100644 --- a/dep/efsw/src/efsw/platform/win/ThreadImpl.hpp +++ b/dep/efsw/src/efsw/platform/win/ThreadImpl.hpp @@ -21,6 +21,8 @@ class ThreadImpl { public: ThreadImpl( Thread * owner ); + + ~ThreadImpl(); void wait(); |