mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 17:54:48 +01:00
Dep: Update efsw to version 1.0.0
This commit is contained in:
@@ -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/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
repo: 78c2ea8c48b213ee0078d6326a1dd719d0844764
|
||||
node: ff0b69daeca1edf7785a8a580518e462be5a6f3d
|
||||
node: e4ead877688b6cd736a2326fb10507fa01c26f8f
|
||||
branch: default
|
||||
latesttag: null
|
||||
latesttagdistance: 144
|
||||
latesttag: 1.0.0
|
||||
latesttagdistance: 1
|
||||
changessincelatesttag: 1
|
||||
|
||||
@@ -44,6 +44,8 @@ void DirectorySnapshot::deleteAll( DirectorySnapshotDiff& Diff )
|
||||
Diff.FilesDeleted.push_back( fi );
|
||||
}
|
||||
}
|
||||
|
||||
Files.clear();
|
||||
}
|
||||
|
||||
void DirectorySnapshot::setDirectoryInfo( std::string directory )
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,16 +135,16 @@ void FileWatcherGeneric::run()
|
||||
{
|
||||
do
|
||||
{
|
||||
mWatchesLock.lock();
|
||||
|
||||
WatchList::iterator it = mWatches.begin();
|
||||
|
||||
for ( ; it != mWatches.end(); it++ )
|
||||
{
|
||||
(*it)->watch();
|
||||
}
|
||||
Lock lock( mWatchesLock);
|
||||
|
||||
mWatchesLock.unlock();
|
||||
WatchList::iterator it = mWatches.begin();
|
||||
|
||||
for ( ; it != mWatches.end(); it++ )
|
||||
{
|
||||
( *it )->watch();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
/// Keep track of the IN_MOVED_FROM events to known if the IN_MOVED_TO event is also fired
|
||||
if ( !wit->second->OldFileName.empty() )
|
||||
wit = mWatches.find( pevent->wd );
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
mWatchesLock.lock();
|
||||
if ( pathInWatches( dir ) )
|
||||
{
|
||||
return Errors::Log::createLastError( Errors::FileRepeated, dir );
|
||||
}
|
||||
|
||||
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();
|
||||
Lock lock( mWatchesLock );
|
||||
|
||||
WatchVector::iterator iter = mWatches.begin();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FileWatcherWin32::removeWatch(WatcherStructWin32* watch)
|
||||
{
|
||||
mWatchesRemoved.insert(watch);
|
||||
|
||||
if( NULL == mThread )
|
||||
{
|
||||
removeWatches();
|
||||
}
|
||||
}
|
||||
|
||||
void FileWatcherWin32::removeWatches()
|
||||
{
|
||||
Lock lock( mWatchesLock );
|
||||
|
||||
Watches::iterator remWatchIter = mWatchesRemoved.begin();
|
||||
|
||||
for( ; remWatchIter != mWatchesRemoved.end(); ++remWatchIter )
|
||||
{
|
||||
Watches::iterator iter = mWatches.find(*remWatchIter);
|
||||
|
||||
if( iter != mWatches.end() )
|
||||
{
|
||||
DestroyWatch(*iter);
|
||||
|
||||
mWatches.erase( iter );
|
||||
}
|
||||
|
||||
// Remove handle from the handle vector
|
||||
HandleVector::iterator it = mHandles.begin();
|
||||
iter = mWatchesNew.find(*remWatchIter);
|
||||
|
||||
for ( ; it != mHandles.end(); it++ )
|
||||
{
|
||||
if ( watch->Watch->DirHandle == (*it) )
|
||||
{
|
||||
mHandles.erase( it );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DestroyWatch(watch);
|
||||
|
||||
break;
|
||||
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 ];
|
||||
Lock lock( mWatchesLock );
|
||||
|
||||
// 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 )
|
||||
for( Watches::iterator iter = mWatches.begin() ; iter != mWatches.end(); ++iter )
|
||||
{
|
||||
watch->Overlapped = OVERLAPPED();
|
||||
RefreshWatch(watch);
|
||||
}
|
||||
WatcherStructWin32 * watch = *iter;
|
||||
|
||||
// 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 )
|
||||
{
|
||||
DWORD bytes;
|
||||
|
||||
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 )
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
27
dep/efsw/src/efsw/Lock.hpp
Normal file
27
dep/efsw/src/efsw/Lock.hpp
Normal file
@@ -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
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -21,6 +21,8 @@ class ThreadImpl
|
||||
{
|
||||
public:
|
||||
ThreadImpl( Thread * owner );
|
||||
|
||||
~ThreadImpl();
|
||||
|
||||
void wait();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user