diff options
author | daMaex <damaex@live.de> | 2019-11-05 18:38:30 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2019-11-05 18:38:30 +0100 |
commit | ed2c2941a74ec720c5e4db3cb33367235e6c3655 (patch) | |
tree | b2a41b9507f2c1c98094abae6b1e697dc5d73bdb | |
parent | c79571a09678a5aefe9e7f0d7a936932e0727b2e (diff) |
Dep/efsw: updated efsw to newest version (#23894)
23 files changed, 404 insertions, 142 deletions
diff --git a/dep/PackageList.txt b/dep/PackageList.txt index 436abd779af..bdad2113e47 100644 --- a/dep/PackageList.txt +++ b/dep/PackageList.txt @@ -18,7 +18,7 @@ cotire (CMake module to speed up builds) efws (Entropia File System Watcher - crossplatform file system watcher) https://bitbucket.org/SpartanJ/efsw - Version: 1.0.0 9a7cbec70b8a88b2e876a382f57c59f3796da0d9 + Version: 1.0.0 e6afbec564e249771046c714b0c7f2154e4c7fef fmt (a small, safe and fast formatting library) https://github.com/fmtlib/fmt diff --git a/dep/efsw/.hg_archival.txt b/dep/efsw/.hg_archival.txt index 9fe34b1c56e..f590482107c 100644 --- a/dep/efsw/.hg_archival.txt +++ b/dep/efsw/.hg_archival.txt @@ -1,6 +1,6 @@ repo: 78c2ea8c48b213ee0078d6326a1dd719d0844764 -node: e4ead877688b6cd736a2326fb10507fa01c26f8f +node: e6afbec564e249771046c714b0c7f2154e4c7fef branch: default latesttag: 1.0.0 -latesttagdistance: 1 -changessincelatesttag: 1 +latesttagdistance: 12 +changessincelatesttag: 12 diff --git a/dep/efsw/CMakeLists.txt b/dep/efsw/CMakeLists.txt index b37e5021e0a..03f6c153115 100644 --- a/dep/efsw/CMakeLists.txt +++ b/dep/efsw/CMakeLists.txt @@ -18,50 +18,48 @@ if (BUILD_SHARED_LIBS) src/efsw/Watcher.cpp src/efsw/WatcherGeneric.cpp) - if(WIN32) - list(APPEND SRCS + if (WIN32) + list (APPEND SRCS src/efsw/platform/win/FileSystemImpl.cpp src/efsw/platform/win/MutexImpl.cpp src/efsw/platform/win/SystemImpl.cpp src/efsw/platform/win/ThreadImpl.cpp) - else() - list(APPEND SRCS + else () + list (APPEND SRCS src/efsw/platform/posix/FileSystemImpl.cpp src/efsw/platform/posix/MutexImpl.cpp src/efsw/platform/posix/SystemImpl.cpp src/efsw/platform/posix/ThreadImpl.cpp) endif() - if (WIN32) - list(APPEND SRCS - src/efsw/WatcherWin32.cpp - src/efsw/FileWatcherWin32.cpp) + if (APPLE) + list (APPEND SRCS + src/efsw/FileWatcherFSEvents.cpp + src/efsw/FileWatcherKqueue.cpp + src/efsw/WatcherFSEvents.cpp + src/efsw/WatcherKqueue.cpp) + + exec_program(uname ARGS -v OUTPUT_VARIABLE OSX_VERSION) + string(REGEX MATCH "[0-9]+" OSX_VERSION ${OSX_VERSION}) + if (NOT OSX_VERSION GREATER 9) + set(OPTIONAL_COMPILE_DEFINITIONS "-DEFSW_FSEVENTS_NOT_SUPPORTED") + endif() + set(OPTIONAL_LINK_LIBRARIES "-framework CoreFoundation" "-framework CoreServices") + elseif (WIN32) + list (APPEND SRCS + src/efsw/FileWatcherWin32.cpp + src/efsw/WatcherWin32.cpp) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - list(APPEND SRCS + list (APPEND SRCS src/efsw/FileWatcherInotify.cpp src/efsw/WatcherInotify.cpp) - if (NOT EXISTS "/usr/include/sys/inotify.h" AND NOT EXISTS "/usr/local/include/sys/inotify.h") - add_definitions(-DEFSW_INOTIFY_NOSYS) + set(OPTIONAL_COMPILE_DEFINITIONS "-DEFSW_INOTIFY_NOSYS") endif() - elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR APPLE) - list(APPEND SRCS + elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + list (APPEND SRCS src/efsw/FileWatcherKqueue.cpp src/efsw/WatcherKqueue.cpp) - - if (APPLE) - list(APPEND SRCS - src/efsw/FileWatcherFSEvents.cpp - src/efsw/WatcherFSEvents.cpp) - - exec_program(uname ARGS -v OUTPUT_VARIABLE OSX_VERSION) - string(REGEX MATCH "[0-9]+" OSX_VERSION ${OSX_VERSION}) - if (NOT OSX_VERSION GREATER 9) - add_definitions(-DEFSW_FSEVENTS_NOT_SUPPORTED) - endif() - - set(OPTIONAL_MAC_LINK_LIBRARIES "-framework CoreFoundation" "-framework CoreServices") - endif() endif() add_library(efsw STATIC ${SRCS}) @@ -72,17 +70,21 @@ if (BUILD_SHARED_LIBS) PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) + target_compile_definitions(efsw + PRIVATE + ${OPTIONAL_COMPILE_DEFINITIONS}) + target_link_libraries(efsw PRIVATE trinity-dependency-interface PUBLIC threads - ${OPTIONAL_MAC_LINK_LIBRARIES}) + ${OPTIONAL_LINK_LIBRARIES}) set_target_properties(efsw PROPERTIES FOLDER "dep") -else() +else () add_library(efsw INTERFACE IMPORTED GLOBAL) -endif() +endif () diff --git a/dep/efsw/README.md b/dep/efsw/README.md index fda0bb599aa..f653088d575 100644 --- a/dep/efsw/README.md +++ b/dep/efsw/README.md @@ -29,57 +29,58 @@ This should never happen, except for the Kqueue implementation, see `Platform li **Some example code:** -------------------- - :::c++ - // Inherits from the abstract listener class, and implements the the file action handler - class UpdateListener : public efsw::FileWatchListener +```c++ +// Inherits from the abstract listener class, and implements the the file action handler +class UpdateListener : public efsw::FileWatchListener +{ +public: + UpdateListener() {} + + void handleFileAction( efsw::WatchID watchid, const std::string& dir, const std::string& filename, efsw::Action action, std::string oldFilename = "" ) { - public: - UpdateListener() {} - - void handleFileAction( efsw::WatchID watchid, const std::string& dir, const std::string& filename, efsw::Action action, std::string oldFilename = "" ) + switch( action ) { - switch( action ) - { - case efsw::Actions::Add: - std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Added" << std::endl; - break; - case efsw::Actions::Delete: - std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Delete" << std::endl; - break; - case efsw::Actions::Modified: - std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Modified" << std::endl; - break; - case efsw::Actions::Moved: - std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Moved from (" << oldFilename << ")" << std::endl; - break; - default: - std::cout << "Should never happen!" << std::endl; - } + case efsw::Actions::Add: + std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Added" << std::endl; + break; + case efsw::Actions::Delete: + std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Delete" << std::endl; + break; + case efsw::Actions::Modified: + std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Modified" << std::endl; + break; + case efsw::Actions::Moved: + std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Moved from (" << oldFilename << ")" << std::endl; + break; + default: + std::cout << "Should never happen!" << std::endl; } - }; + } +}; + +// Create the file system watcher instance +// efsw::FileWatcher allow a first boolean parameter that indicates if it should start with the generic file watcher instead of the platform specific backend +efsw::FileWatcher * fileWatcher = new efsw::FileWatcher(); - // Create the file system watcher instance - // efsw::FileWatcher allow a first boolean parameter that indicates if it should start with the generic file watcher instead of the platform specific backend - efsw::FileWatcher * fileWatcher = new efsw::FileWatcher(); +// Create the instance of your efsw::FileWatcherListener implementation +UpdateListener * listener = new UpdateListener(); - // Create the instance of your efsw::FileWatcherListener implementation - UpdateListener * listener = new UpdateListener(); +// Add a folder to watch, and get the efsw::WatchID +// It will watch the /tmp folder recursively ( the third parameter indicates that is recursive ) +// Reporting the files and directories changes to the instance of the listener +efsw::WatchID watchID = fileWatcher->addWatch( "/tmp", listener, true ); - // Add a folder to watch, and get the efsw::WatchID - // It will watch the /tmp folder recursively ( the third parameter indicates that is recursive ) - // Reporting the files and directories changes to the instance of the listener - efsw::WatchID watchID = fileWatcher->addWatch( "/tmp", listener, true ); +// Adds another directory to watch. This time as non-recursive. +efsw::WatchID watchID2 = fileWatcher->addWatch( "/usr", listener, false ); - // Adds another directory to watch. This time as non-recursive. - efsw::WatchID watchID2 = fileWatcher->addWatch( "/usr", listener, false ); +// Start watching asynchronously the directories +fileWatcher->watch(); - // Start watching asynchronously the directories - fileWatcher.watch(); +// Remove the second watcher added +// You can also call removeWatch by passing the watch path ( it must end with an slash or backslash in windows, since that's how internally it's saved ) +fileWatcher->removeWatch( watchID2 ); +``` - // Remove the second watcher added - // You can also call removeWatch by passing the watch path ( it must end with an slash or backslash in windows, since that's how internally it's saved ) - fileWatcher->removeWatch( watchID2 ); - **Dependencies** -------------- None :) diff --git a/dep/efsw/include/efsw/efsw.hpp b/dep/efsw/include/efsw/efsw.hpp index 0693bb296f0..72ae1a61d7c 100644 --- a/dep/efsw/include/efsw/efsw.hpp +++ b/dep/efsw/include/efsw/efsw.hpp @@ -121,7 +121,7 @@ class EFSW_API FileWatcher FileWatcher(); /// Constructor that lets you force the use of the Generic File Watcher - FileWatcher( bool useGenericFileWatcher ); + explicit FileWatcher( bool useGenericFileWatcher ); virtual ~FileWatcher(); @@ -178,10 +178,6 @@ class EFSW_API FileWatcher class FileWatchListener { public: - FileWatchListener() {} - - virtual ~FileWatchListener() {} - /// Handles the action file action /// @param watchid The watch id for the directory /// @param dir The directory diff --git a/dep/efsw/src/efsw/DirWatcherGeneric.cpp b/dep/efsw/src/efsw/DirWatcherGeneric.cpp index b80c14d24ce..a5751148863 100644 --- a/dep/efsw/src/efsw/DirWatcherGeneric.cpp +++ b/dep/efsw/src/efsw/DirWatcherGeneric.cpp @@ -58,7 +58,7 @@ DirWatcherGeneric::~DirWatcherGeneric() DirWatchMap::iterator it = Directories.begin(); - for ( ; it != Directories.end(); it++ ) + for ( ; it != Directories.end(); ++it ) { if ( Deleted ) { @@ -218,7 +218,7 @@ void DirWatcherGeneric::watch( bool reportOwnChange ) } /// Process the subdirectories looking for changes - for ( DirWatchMap::iterator dit = Directories.begin(); dit != Directories.end(); dit++ ) + for ( DirWatchMap::iterator dit = Directories.begin(); dit != Directories.end(); ++dit ) { /// Just watch dit->second->watch(); @@ -293,7 +293,7 @@ DirWatcherGeneric * DirWatcherGeneric::findDirWatcher( std::string dir ) { DirWatcherGeneric * watcher = NULL; - for ( DirWatchMap::iterator it = Directories.begin(); it != Directories.end(); it++ ) + for ( DirWatchMap::iterator it = Directories.begin(); it != Directories.end(); ++it ) { watcher = it->second->findDirWatcher( dir ); @@ -437,7 +437,7 @@ bool DirWatcherGeneric::pathInWatches( std::string path ) return true; } - for ( DirWatchMap::iterator it = Directories.begin(); it != Directories.end(); it++ ) + for ( DirWatchMap::iterator it = Directories.begin(); it != Directories.end(); ++it ) { if ( it->second->pathInWatches( path ) ) { diff --git a/dep/efsw/src/efsw/FileInfo.cpp b/dep/efsw/src/efsw/FileInfo.cpp index 7b405949698..f5518225b48 100644 --- a/dep/efsw/src/efsw/FileInfo.cpp +++ b/dep/efsw/src/efsw/FileInfo.cpp @@ -180,17 +180,17 @@ bool FileInfo::operator==( const FileInfo& Other ) const ); } -bool FileInfo::isDirectory() +bool FileInfo::isDirectory() const { return 0 != S_ISDIR(Permissions); } -bool FileInfo::isRegularFile() +bool FileInfo::isRegularFile() const { return 0 != S_ISREG(Permissions); } -bool FileInfo::isReadable() +bool FileInfo::isReadable() const { #if EFSW_PLATFORM != EFSW_PLATFORM_WIN32 static bool isRoot = getuid() == 0; @@ -200,7 +200,7 @@ bool FileInfo::isReadable() #endif } -bool FileInfo::isLink() +bool FileInfo::isLink() const { #if EFSW_PLATFORM != EFSW_PLATFORM_WIN32 return S_ISLNK(Permissions); diff --git a/dep/efsw/src/efsw/FileInfo.hpp b/dep/efsw/src/efsw/FileInfo.hpp index 45cca6a7953..c86e5749a70 100644 --- a/dep/efsw/src/efsw/FileInfo.hpp +++ b/dep/efsw/src/efsw/FileInfo.hpp @@ -29,15 +29,15 @@ class FileInfo FileInfo& operator=( const FileInfo& Other ); - bool isDirectory(); + bool isDirectory() const; - bool isRegularFile(); + bool isRegularFile() const; - bool isReadable(); + bool isReadable() const; bool sameInode( const FileInfo& Other ) const; - bool isLink(); + bool isLink() const; std::string linksTo(); diff --git a/dep/efsw/src/efsw/FileSystem.cpp b/dep/efsw/src/efsw/FileSystem.cpp index e3afa0b4046..1bca40558c6 100644 --- a/dep/efsw/src/efsw/FileSystem.cpp +++ b/dep/efsw/src/efsw/FileSystem.cpp @@ -121,4 +121,14 @@ bool FileSystem::isRemoteFS( const std::string& directory ) return Platform::FileSystem::isRemoteFS( directory ); } +bool FileSystem::changeWorkingDirectory( const std::string& directory ) +{ + return Platform::FileSystem::changeWorkingDirectory( directory ); +} + +std::string FileSystem::getCurrentWorkingDirectory() +{ + return Platform::FileSystem::getCurrentWorkingDirectory(); +} + } diff --git a/dep/efsw/src/efsw/FileSystem.hpp b/dep/efsw/src/efsw/FileSystem.hpp index 4e2e1aeb7cd..07c7ade8baa 100644 --- a/dep/efsw/src/efsw/FileSystem.hpp +++ b/dep/efsw/src/efsw/FileSystem.hpp @@ -33,6 +33,10 @@ class FileSystem static std::string precomposeFileName(const std::string& name); static bool isRemoteFS( const std::string& directory ); + + static bool changeWorkingDirectory( const std::string & path ); + + static std::string getCurrentWorkingDirectory(); }; } diff --git a/dep/efsw/src/efsw/FileWatcherCWrapper.cpp b/dep/efsw/src/efsw/FileWatcherCWrapper.cpp index 2739e756bb2..30a36eacc35 100644 --- a/dep/efsw/src/efsw/FileWatcherCWrapper.cpp +++ b/dep/efsw/src/efsw/FileWatcherCWrapper.cpp @@ -12,12 +12,11 @@ public: efsw_pfn_fileaction_callback mFn; void* mParam; public: - Watcher_CAPI(efsw_watcher watcher, efsw_pfn_fileaction_callback fn, void* param) - { - mWatcher = watcher; - mFn = fn; - mParam = param; - } + Watcher_CAPI(efsw_watcher watcher, efsw_pfn_fileaction_callback fn, void* param) : + mWatcher( watcher ), + mFn( fn ), + mParam( param ) + {} void handleFileAction(efsw::WatchID watchid, const std::string& dir, const std::string& filename, efsw::Action action, std::string oldFilename = "") @@ -34,7 +33,7 @@ static std::vector<Watcher_CAPI*> g_callbacks; Watcher_CAPI* find_callback(efsw_watcher watcher, efsw_pfn_fileaction_callback fn) { - for (std::vector<Watcher_CAPI*>::iterator i = g_callbacks.begin(); i != g_callbacks.end(); i++ ) + for (std::vector<Watcher_CAPI*>::iterator i = g_callbacks.begin(); i != g_callbacks.end(); ++i ) { Watcher_CAPI* callback = *i; @@ -55,7 +54,7 @@ Watcher_CAPI* remove_callback(efsw_watcher watcher) if (callback->mWatcher == watcher) i = g_callbacks.erase(i); else - i++; + ++i; } return NULL; diff --git a/dep/efsw/src/efsw/FileWatcherFSEvents.cpp b/dep/efsw/src/efsw/FileWatcherFSEvents.cpp index 524b6f1bb3b..5aac14282c9 100644 --- a/dep/efsw/src/efsw/FileWatcherFSEvents.cpp +++ b/dep/efsw/src/efsw/FileWatcherFSEvents.cpp @@ -218,7 +218,7 @@ void FileWatcherFSEvents::run() { if ( !mNeedInit.empty() ) { - for ( std::list<WatcherFSEvents*>::iterator it = mNeedInit.begin(); it != mNeedInit.end(); it++ ) + for ( std::list<WatcherFSEvents*>::iterator it = mNeedInit.begin(); it != mNeedInit.end(); ++it ) { (*it)->initAsync(); } @@ -244,7 +244,7 @@ std::list<std::string> FileWatcherFSEvents::directories() Lock lock( mWatchesLock ); - for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) + for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); ++it ) { dirs.push_back( std::string( it->second->Directory ) ); } @@ -254,7 +254,7 @@ std::list<std::string> FileWatcherFSEvents::directories() bool FileWatcherFSEvents::pathInWatches( const std::string& path ) { - for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) + for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); ++it ) { if ( it->second->Directory == path ) { diff --git a/dep/efsw/src/efsw/FileWatcherFSEvents.hpp b/dep/efsw/src/efsw/FileWatcherFSEvents.hpp index 6aafbc0b5ea..9a2c956ed10 100644 --- a/dep/efsw/src/efsw/FileWatcherFSEvents.hpp +++ b/dep/efsw/src/efsw/FileWatcherFSEvents.hpp @@ -33,9 +33,7 @@ enum FSEventEvents efswFSEventStreamEventFlagItemIsSymlink = 0x00040000, efswFSEventsModified = efswFSEventStreamEventFlagItemFinderInfoMod | efswFSEventStreamEventFlagItemModified | - efswFSEventStreamEventFlagItemInodeMetaMod | - efswFSEventStreamEventFlagItemChangeOwner | - efswFSEventStreamEventFlagItemXattrMod + efswFSEventStreamEventFlagItemInodeMetaMod }; /// Implementation for Win32 based on ReadDirectoryChangesW. diff --git a/dep/efsw/src/efsw/FileWatcherGeneric.cpp b/dep/efsw/src/efsw/FileWatcherGeneric.cpp index 6a37c025492..fd423b1476b 100644 --- a/dep/efsw/src/efsw/FileWatcherGeneric.cpp +++ b/dep/efsw/src/efsw/FileWatcherGeneric.cpp @@ -24,7 +24,7 @@ FileWatcherGeneric::~FileWatcherGeneric() /// Delete the watches WatchList::iterator it = mWatches.begin(); - for ( ; it != mWatches.end(); it++ ) + for ( ; it != mWatches.end(); ++it ) { efSAFE_DELETE( (*it) ); } @@ -84,7 +84,7 @@ void FileWatcherGeneric::removeWatch( const std::string& directory ) { WatchList::iterator it = mWatches.begin(); - for ( ; it != mWatches.end(); it++ ) + for ( ; it != mWatches.end(); ++it ) { if ( (*it)->Directory == directory ) { @@ -105,7 +105,7 @@ void FileWatcherGeneric::removeWatch(WatchID watchid) { WatchList::iterator it = mWatches.begin(); - for ( ; it != mWatches.end(); it++ ) + for ( ; it != mWatches.end(); ++it ) { if ( (*it)->ID == watchid ) { @@ -140,7 +140,7 @@ void FileWatcherGeneric::run() WatchList::iterator it = mWatches.begin(); - for ( ; it != mWatches.end(); it++ ) + for ( ; it != mWatches.end(); ++it ) { ( *it )->watch(); } @@ -150,7 +150,7 @@ void FileWatcherGeneric::run() } while ( mInitOK ); } -void FileWatcherGeneric::handleAction(Watcher * watch, const std::string& filename, unsigned long action, std::string oldFilename) +void FileWatcherGeneric::handleAction(Watcher *, const std::string&, unsigned long, std::string) { /// Not used } @@ -163,7 +163,7 @@ std::list<std::string> FileWatcherGeneric::directories() WatchList::iterator it = mWatches.begin(); - for ( ; it != mWatches.end(); it++ ) + for ( ; it != mWatches.end(); ++it ) { dirs.push_back( (*it)->Directory ); } @@ -175,7 +175,7 @@ bool FileWatcherGeneric::pathInWatches( const std::string& path ) { WatchList::iterator it = mWatches.begin(); - for ( ; it != mWatches.end(); it++ ) + for ( ; it != mWatches.end(); ++it ) { if ( (*it)->Directory == path || (*it)->pathInWatches( path ) ) { diff --git a/dep/efsw/src/efsw/FileWatcherInotify.cpp b/dep/efsw/src/efsw/FileWatcherInotify.cpp index 6c10271994a..71ae3bcd97d 100644 --- a/dep/efsw/src/efsw/FileWatcherInotify.cpp +++ b/dep/efsw/src/efsw/FileWatcherInotify.cpp @@ -19,6 +19,7 @@ #include <efsw/System.hpp> #include <efsw/Debug.hpp> #include <efsw/Lock.hpp> +#include <efsw/String.hpp> #define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024) @@ -161,13 +162,13 @@ WatchID FileWatcherInotify::addWatch( const std::string& directory, FileWatchLis std::map<std::string, FileInfo> files = FileSystem::filesInfoFromPath( pWatch->Directory ); std::map<std::string, FileInfo>::iterator it = files.begin(); - for ( ; it != files.end(); it++ ) + for ( ; it != files.end(); ++it ) { - FileInfo fi = it->second; + const FileInfo& cfi = it->second; - if ( fi.isDirectory() && fi.isReadable() ) + if ( cfi.isDirectory() && cfi.isReadable() ) { - addWatch( fi.Filepath, watcher, recursive, pWatch ); + addWatch( cfi.Filepath, watcher, recursive, pWatch ); } } } @@ -196,7 +197,7 @@ void FileWatcherInotify::removeWatchLocked(WatchID watchid) } } - for ( std::list<WatchID>::iterator eit = eraseWatches.begin(); eit != eraseWatches.end(); eit++ ) + for ( std::list<WatchID>::iterator eit = eraseWatches.begin(); eit != eraseWatches.end(); ++eit ) { removeWatch( *eit ); } @@ -253,7 +254,7 @@ void FileWatcherInotify::removeWatch(const std::string& directory) } } - for ( std::list<WatchID>::iterator eit = eraseWatches.begin(); eit != eraseWatches.end(); eit++ ) + for ( std::list<WatchID>::iterator eit = eraseWatches.begin(); eit != eraseWatches.end(); ++eit ) { removeWatchLocked( *eit ); } @@ -312,6 +313,25 @@ void FileWatcherInotify::watch() } } +Watcher * FileWatcherInotify::watcherContainsDirectory( std::string dir ) +{ + FileSystem::dirRemoveSlashAtEnd( dir ); + std::string watcherPath = FileSystem::pathRemoveFileName( dir ); + FileSystem::dirAddSlashAtEnd( watcherPath ); + + for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); ++it ) + { + Watcher * watcher = it->second; + + if ( watcher->Directory == watcherPath ) + { + return watcher; + } + } + + return NULL; +} + void FileWatcherInotify::run() { static char buff[BUFF_SIZE] = {0}; @@ -329,12 +349,14 @@ void FileWatcherInotify::run() if( select (FD_SETSIZE, &rfds, NULL, NULL, &timeout) > 0 ) { - ssize_t len, i = 0; + ssize_t len; len = read (mFD, buff, BUFF_SIZE); if (len != -1) { + ssize_t i = 0; + while (i < len) { struct inotify_event *pevent = (struct inotify_event *)&buff[i]; @@ -348,7 +370,7 @@ void FileWatcherInotify::run() { 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 + /// Keep track of the IN_MOVED_FROM events to know if the IN_MOVED_TO event is also fired if ( !wit->second->OldFileName.empty() ) { movedOutsideWatches.push_back( wit->second ); @@ -362,15 +384,44 @@ void FileWatcherInotify::run() if ( !movedOutsideWatches.empty() ) { /// In case that the IN_MOVED_TO is never fired means that the file was moved to other folder - for ( std::list<WatcherInotify*>::iterator it = movedOutsideWatches.begin(); it != movedOutsideWatches.end(); it++ ) + for ( std::list<WatcherInotify*>::iterator it = movedOutsideWatches.begin(); it != movedOutsideWatches.end(); ++it ) { - if ( !(*it)->OldFileName.empty() ) + Watcher * watch = (*it); + + if ( !watch->OldFileName.empty() ) { - /// So we send a IN_DELETE event for files that where moved outside of our scope - handleAction( *it, (*it)->OldFileName, IN_DELETE ); + /// Check if the file move was a folder already being watched + std::list<Watcher*> eraseWatches; + + for(; wit != mWatches.end(); ++wit) + { + Watcher * oldWatch = wit->second; + + if ( oldWatch != watch && + -1 != String::strStartsWith( watch->Directory + watch->OldFileName + "/", oldWatch->Directory ) ) + { + eraseWatches.push_back( oldWatch ); + } + } + + /// Remove invalid watches + eraseWatches.sort(); + + for ( std::list<Watcher*>::reverse_iterator eit = eraseWatches.rbegin(); eit != eraseWatches.rend(); ++eit ) + { + Watcher * rmWatch = *eit; + + /// Create Delete event for removed watches that have been moved too + if ( Watcher * cntWatch = watcherContainsDirectory( rmWatch->Directory ) ) + { + handleAction( cntWatch, FileSystem::fileNameFromPath( rmWatch->Directory ), IN_DELETE ); + } + + removeWatch( rmWatch->ID ); + } /// Remove the OldFileName - (*it)->OldFileName = ""; + watch->OldFileName = ""; } } @@ -391,7 +442,7 @@ void FileWatcherInotify::checkForNewWatcher( Watcher* watch, std::string fpath ) bool found = false; /// First check if exists - for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) + for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); ++it ) { if ( it->second->Directory == fpath ) { @@ -407,7 +458,7 @@ void FileWatcherInotify::checkForNewWatcher( Watcher* watch, std::string fpath ) } } -void FileWatcherInotify::handleAction( Watcher* watch, const std::string& filename, unsigned long action, std::string oldFilename ) +void FileWatcherInotify::handleAction( Watcher* watch, const std::string& filename, unsigned long action, std::string ) { if ( !watch || !watch->Listener ) { @@ -443,7 +494,7 @@ void FileWatcherInotify::handleAction( Watcher* watch, const std::string& filena FileSystem::dirAddSlashAtEnd( opath ); FileSystem::dirAddSlashAtEnd( fpath ); - for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) + for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); ++it ) { if ( it->second->Directory == opath && it->second->DirInfo.Inode == FileInfo( opath ).Inode ) { @@ -476,7 +527,7 @@ void FileWatcherInotify::handleAction( Watcher* watch, const std::string& filena /// If the file erased is a directory and recursive is enabled, removes the directory erased if ( watch->Recursive ) { - for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) + for ( WatchMap::iterator it = mWatches.begin(); it != mWatches.end(); ++it ) { if ( it->second->Directory == fpath ) { @@ -496,7 +547,7 @@ std::list<std::string> FileWatcherInotify::directories() WatchMap::iterator it = mRealWatches.begin(); - for ( ; it != mRealWatches.end(); it++ ) + for ( ; it != mRealWatches.end(); ++it ) { dirs.push_back( it->second->Directory ); } @@ -509,7 +560,7 @@ bool FileWatcherInotify::pathInWatches( const std::string& path ) /// Search in the real watches, since it must allow adding a watch already watched as a subdir WatchMap::iterator it = mRealWatches.begin(); - for ( ; it != mRealWatches.end(); it++ ) + for ( ; it != mRealWatches.end(); ++it ) { if ( it->second->Directory == path ) { diff --git a/dep/efsw/src/efsw/FileWatcherInotify.hpp b/dep/efsw/src/efsw/FileWatcherInotify.hpp index 43ee9ca6afc..b68314050a1 100644 --- a/dep/efsw/src/efsw/FileWatcherInotify.hpp +++ b/dep/efsw/src/efsw/FileWatcherInotify.hpp @@ -64,6 +64,8 @@ class FileWatcherInotify : public FileWatcherImpl void removeWatchLocked(WatchID watchid); void checkForNewWatcher( Watcher* watch, std::string fpath ); + + Watcher * watcherContainsDirectory( std::string dir ); }; } diff --git a/dep/efsw/src/efsw/FileWatcherKqueue.cpp b/dep/efsw/src/efsw/FileWatcherKqueue.cpp index d8a76b8995b..3373a68d0ce 100644 --- a/dep/efsw/src/efsw/FileWatcherKqueue.cpp +++ b/dep/efsw/src/efsw/FileWatcherKqueue.cpp @@ -118,10 +118,10 @@ WatchID FileWatcherKqueue::addWatch(const std::string& directory, FileWatchListe // Probably the folder has too many files, create a generic watcher if ( EACCES != le ) { - WatcherGeneric * watch = new WatcherGeneric( ++mLastWatchID, dir, watcher, this, recursive ); + WatcherGeneric * genericWatch = new WatcherGeneric( ++mLastWatchID, dir, watcher, this, recursive ); Lock lock( mWatchesLock ); - mWatches.insert(std::make_pair(mLastWatchID, watch)); + mWatches.insert(std::make_pair(mLastWatchID, genericWatch)); } else { @@ -223,7 +223,7 @@ std::list<std::string> FileWatcherKqueue::directories() WatchMap::iterator it = mWatches.begin(); - for ( ; it != mWatches.end(); it++ ) + for ( ; it != mWatches.end(); ++it ) { dirs.push_back( it->second->Directory ); } @@ -235,7 +235,7 @@ bool FileWatcherKqueue::pathInWatches( const std::string& path ) { WatchMap::iterator it = mWatches.begin(); - for ( ; it != mWatches.end(); it++ ) + for ( ; it != mWatches.end(); ++it ) { if ( it->second->Directory == path ) { diff --git a/dep/efsw/src/efsw/FileWatcherWin32.cpp b/dep/efsw/src/efsw/FileWatcherWin32.cpp index 4e85fc3dd00..317506fb3e3 100644 --- a/dep/efsw/src/efsw/FileWatcherWin32.cpp +++ b/dep/efsw/src/efsw/FileWatcherWin32.cpp @@ -209,7 +209,7 @@ void FileWatcherWin32::run() removeWatches(); - for ( Watches::iterator it = mWatchesNew.begin(); it != mWatchesNew.end(); it++ ) + for ( Watches::iterator it = mWatchesNew.begin(); it != mWatchesNew.end(); ++it ) { RefreshWatch(*it); } @@ -246,7 +246,7 @@ void FileWatcherWin32::handleAction(Watcher* watch, const std::string& filename, FileSystem::dirAddSlashAtEnd( opath ); FileSystem::dirAddSlashAtEnd( fpath ); - for ( Watches::iterator it = mWatches.begin(); it != mWatches.end(); it++ ) + for ( Watches::iterator it = mWatches.begin(); it != mWatches.end(); ++it ) { if ( (*it)->Watch->Directory == opath ) { @@ -287,7 +287,7 @@ std::list<std::string> FileWatcherWin32::directories() Lock lock( mWatchesLock ); - for ( Watches::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 ) ); } @@ -297,7 +297,7 @@ std::list<std::string> FileWatcherWin32::directories() bool FileWatcherWin32::pathInWatches( const std::string& path ) { - for ( Watches::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/inotify-nosys.h b/dep/efsw/src/efsw/inotify-nosys.h index 75df5d3ced3..be1e627d962 100644 --- a/dep/efsw/src/efsw/inotify-nosys.h +++ b/dep/efsw/src/efsw/inotify-nosys.h @@ -69,6 +69,11 @@ struct inotify_event { # define __NR_inotify_add_watch (__NR_SYSCALL_BASE+317) # define __NR_inotify_rm_watch (__NR_SYSCALL_BASE+318) +#elif defined (__aarch64__) +# define __NR_inotify_init 1043 +# define __NR_inotify_add_watch 27 +# define __NR_inotify_rm_watch 28 + #elif defined (__frv__) # define __NR_inotify_init 291 # define __NR_inotify_add_watch 292 diff --git a/dep/efsw/src/efsw/platform/posix/FileSystemImpl.cpp b/dep/efsw/src/efsw/platform/posix/FileSystemImpl.cpp index e061b25d56b..5795d567740 100644 --- a/dep/efsw/src/efsw/platform/posix/FileSystemImpl.cpp +++ b/dep/efsw/src/efsw/platform/posix/FileSystemImpl.cpp @@ -5,6 +5,7 @@ #include <efsw/FileInfo.hpp> #include <efsw/FileSystem.hpp> #include <dirent.h> +#include <unistd.h> #include <cstring> #ifndef _DARWIN_FEATURE_64_BIT_INODE @@ -17,6 +18,7 @@ #include <sys/stat.h> #include <cstdlib> +#include <climits> #if EFSW_OS == EFSW_OS_LINUX || EFSW_OS == EFSW_OS_SOLARIS || EFSW_OS == EFSW_OS_ANDROID #include <sys/vfs.h> @@ -49,8 +51,152 @@ #define S_MAGIC_VMHGFS 0xBACBACBC #define S_MAGIC_VXFS 0xA501FCF5 +#if EFSW_OS == EFSW_OS_LINUX +#include <mntent.h> +#include <cstdio> +#endif + namespace efsw { namespace Platform { +#if EFSW_OS == EFSW_OS_LINUX + +#pragma pack(push, 1) +struct ntfs_super_block +{ + char jump[3]; + char oem_id[8]; +}; +#pragma pack(pop) + +bool isNTFS( std::string device ) +{ + FILE * fd = fopen( device.c_str(), "r" ); + + ntfs_super_block ns; + + if ( fd != NULL ) + { + fread( &ns, 1, sizeof(ntfs_super_block), fd ); + fclose( fd ); + + std::string oemId( ns.oem_id ); + + return oemId.compare(0, 4, "NTFS") == 0; + } + + return false; +} + +std::string findMountPoint( std::string file ) +{ + std::string cwd = FileSystem::getCurrentWorkingDirectory(); + struct stat last_stat; + struct stat file_stat; + + stat( file.c_str(), &file_stat ); + + std::string mp; + + if ( efsw::FileSystem::isDirectory( file ) ) { + last_stat = file_stat; + + if ( !FileSystem::changeWorkingDirectory( file ) ) + return ""; + } else { + std::string dir = efsw::FileSystem::pathRemoveFileName( file ); + + if ( !FileSystem::changeWorkingDirectory( dir ) ) + return ""; + + if (stat (".", &last_stat) < 0) + return ""; + } + + while (true) + { + struct stat st; + + if ( stat("..", &st) < 0 ) + goto done; + + if ( st.st_dev != last_stat.st_dev || st.st_ino == last_stat.st_ino ) + break; + + if ( !FileSystem::changeWorkingDirectory("..") ) + { + goto done; + } + + last_stat = st; + } + + /* Finally reached a mount point, see what it's called. */ + mp = FileSystem::getCurrentWorkingDirectory(); + +done: + FileSystem::changeWorkingDirectory( cwd ); + + return mp; +} + +std::string findDevicePath( const std::string& directory ) +{ + struct mntent *ent; + FILE *aFile; + + aFile = setmntent("/proc/mounts", "r"); + + if ( aFile == NULL ) + return ""; + + while ( NULL != ( ent = getmntent( aFile ) ) ) + { + std::string dirName( ent->mnt_dir ); + + if ( dirName == directory ) + { + std::string fsName( ent->mnt_fsname ); + + endmntent(aFile); + + return fsName; + } + } + + endmntent(aFile); + + return ""; +} + +bool isLocalFUSEDirectory( std::string directory ) +{ + efsw::FileSystem::dirRemoveSlashAtEnd( directory ); + + directory = findMountPoint( directory ); + + if ( !directory.empty() ) + { + std::string devicePath = findDevicePath( directory ); + + return ( !devicePath.empty() && isNTFS( devicePath ) ); + } + + return false; +} + +#endif + +bool FileSystem::changeWorkingDirectory( const std::string & path ) +{ + return -1 != chdir( path.c_str() ); +} + +std::string FileSystem::getCurrentWorkingDirectory() { + char dir[PATH_MAX + 1]; + getcwd( dir, PATH_MAX + 1 ); + return std::string( dir ); +} + FileInfoMap FileSystem::filesInfoFromPath( const std::string& path ) { FileInfoMap files; @@ -104,13 +250,18 @@ bool FileSystem::isRemoteFS( const std::string& directory ) switch ( statfsbuf.f_type | 0UL ) { + case S_MAGIC_FUSEBLK: /* 0x65735546 remote */ + { + #if EFSW_OS == EFSW_OS_LINUX + return !isLocalFUSEDirectory( directory ); + #endif + } case S_MAGIC_AFS: /* 0x5346414F remote */ case S_MAGIC_AUFS: /* 0x61756673 remote */ case S_MAGIC_CEPH: /* 0x00C36400 remote */ case S_MAGIC_CIFS: /* 0xFF534D42 remote */ case S_MAGIC_CODA: /* 0x73757245 remote */ case S_MAGIC_FHGFS: /* 0x19830326 remote */ - case S_MAGIC_FUSEBLK: /* 0x65735546 remote */ case S_MAGIC_FUSECTL: /* 0x65735543 remote */ case S_MAGIC_GFS: /* 0x01161970 remote */ case S_MAGIC_GPFS: /* 0x47504653 remote */ diff --git a/dep/efsw/src/efsw/platform/posix/FileSystemImpl.hpp b/dep/efsw/src/efsw/platform/posix/FileSystemImpl.hpp index 865b3f8dfdf..7353d81cf3f 100644 --- a/dep/efsw/src/efsw/platform/posix/FileSystemImpl.hpp +++ b/dep/efsw/src/efsw/platform/posix/FileSystemImpl.hpp @@ -18,6 +18,10 @@ class FileSystem static bool isDirectory( const std::string& path ); static bool isRemoteFS( const std::string& directory ); + + static bool changeWorkingDirectory( const std::string & path ); + + static std::string getCurrentWorkingDirectory(); }; }} diff --git a/dep/efsw/src/efsw/platform/win/FileSystemImpl.cpp b/dep/efsw/src/efsw/platform/win/FileSystemImpl.cpp index 376a474e662..cf27eb7a0f6 100644 --- a/dep/efsw/src/efsw/platform/win/FileSystemImpl.cpp +++ b/dep/efsw/src/efsw/platform/win/FileSystemImpl.cpp @@ -2,6 +2,7 @@ #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 +#include <climits> #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -9,10 +10,44 @@ #ifndef EFSW_COMPILER_MSVC #include <dirent.h> +#else +#include <direct.h> #endif namespace efsw { namespace Platform { +bool FileSystem::changeWorkingDirectory( const std::string & path ) +{ + int res; +#ifdef EFSW_COMPILER_MSVC + #ifdef UNICODE + res = _wchdir( String::fromUtf8( path.c_str() ).toWideString().c_str() ); + #else + res = _chdir( String::fromUtf8( path.c_str() ).toAnsiString().c_str() ); + #endif +#else + res = chdir( path.c_str() ); +#endif + return -1 != res; +} + +std::string FileSystem::getCurrentWorkingDirectory() +{ +#ifdef EFSW_COMPILER_MSVC + #if defined( UNICODE ) AND !defined( EFSW_NO_WIDECHAR ) + wchar_t dir[_MAX_PATH]; + return ( 0 != GetCurrentDirectoryW( _MAX_PATH, dir ) ) ? String( dir ).toUtf8() : std::string(); + #else + char dir[_MAX_PATH]; + return ( 0 != GetCurrentDirectory( _MAX_PATH, dir ) ) ? String( dir, std::locale() ).toUtf8() : std::string(); + #endif +#else + char dir[PATH_MAX + 1]; + getcwd( dir, PATH_MAX + 1 ); + return std::string( dir ); +#endif +} + FileInfoMap FileSystem::filesInfoFromPath( const std::string& path ) { FileInfoMap files; diff --git a/dep/efsw/src/efsw/platform/win/FileSystemImpl.hpp b/dep/efsw/src/efsw/platform/win/FileSystemImpl.hpp index 597edc4a647..8f6c5ad1837 100644 --- a/dep/efsw/src/efsw/platform/win/FileSystemImpl.hpp +++ b/dep/efsw/src/efsw/platform/win/FileSystemImpl.hpp @@ -19,6 +19,10 @@ class FileSystem static bool isDirectory( const std::string& path ); static bool isRemoteFS( const std::string& directory ); + + static bool changeWorkingDirectory( const std::string & path ); + + static std::string getCurrentWorkingDirectory(); }; }} |