diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-04-09 17:40:13 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-04-09 17:40:13 +0800 |
| commit | 9750786a5c03b5ce3ea22b240d1b3cd34990856b (patch) | |
| tree | e495e43245e1bacc86d33142af202613a82a40c1 /src/3rdParty/efsw/FileWatcher.cpp | |
| parent | 571fb952b99e580a0381f539885f8f175e2ec3b0 (diff) | |
| download | yuescript-9750786a5c03b5ce3ea22b240d1b3cd34990856b.tar.gz yuescript-9750786a5c03b5ce3ea22b240d1b3cd34990856b.tar.bz2 yuescript-9750786a5c03b5ce3ea22b240d1b3cd34990856b.zip | |
Updated efsw. Fixed issue #204.
Diffstat (limited to 'src/3rdParty/efsw/FileWatcher.cpp')
| -rw-r--r--[-rwxr-xr-x] | src/3rdParty/efsw/FileWatcher.cpp | 239 |
1 files changed, 120 insertions, 119 deletions
diff --git a/src/3rdParty/efsw/FileWatcher.cpp b/src/3rdParty/efsw/FileWatcher.cpp index 696a46f..f45b243 100755..100644 --- a/src/3rdParty/efsw/FileWatcher.cpp +++ b/src/3rdParty/efsw/FileWatcher.cpp | |||
| @@ -1,119 +1,120 @@ | |||
| 1 | #include <efsw/FileSystem.hpp> | 1 | #include <efsw/FileSystem.hpp> |
| 2 | #include <efsw/FileWatcherGeneric.hpp> | 2 | #include <efsw/FileWatcherGeneric.hpp> |
| 3 | #include <efsw/FileWatcherImpl.hpp> | 3 | #include <efsw/FileWatcherImpl.hpp> |
| 4 | #include <efsw/efsw.hpp> | 4 | #include <efsw/efsw.hpp> |
| 5 | 5 | ||
| 6 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | 6 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 |
| 7 | #include <efsw/FileWatcherWin32.hpp> | 7 | #include <efsw/FileWatcherWin32.hpp> |
| 8 | #define FILEWATCHER_IMPL FileWatcherWin32 | 8 | #define FILEWATCHER_IMPL FileWatcherWin32 |
| 9 | #define BACKEND_NAME "Win32" | 9 | #define BACKEND_NAME "Win32" |
| 10 | #elif EFSW_PLATFORM == EFSW_PLATFORM_INOTIFY | 10 | #elif EFSW_PLATFORM == EFSW_PLATFORM_INOTIFY |
| 11 | #include <efsw/FileWatcherInotify.hpp> | 11 | #include <efsw/FileWatcherInotify.hpp> |
| 12 | #define FILEWATCHER_IMPL FileWatcherInotify | 12 | #define FILEWATCHER_IMPL FileWatcherInotify |
| 13 | #define BACKEND_NAME "Inotify" | 13 | #define BACKEND_NAME "Inotify" |
| 14 | #elif EFSW_PLATFORM == EFSW_PLATFORM_KQUEUE | 14 | #elif EFSW_PLATFORM == EFSW_PLATFORM_KQUEUE |
| 15 | #include <efsw/FileWatcherKqueue.hpp> | 15 | #include <efsw/FileWatcherKqueue.hpp> |
| 16 | #define FILEWATCHER_IMPL FileWatcherKqueue | 16 | #define FILEWATCHER_IMPL FileWatcherKqueue |
| 17 | #define BACKEND_NAME "Kqueue" | 17 | #define BACKEND_NAME "Kqueue" |
| 18 | #elif EFSW_PLATFORM == EFSW_PLATFORM_FSEVENTS | 18 | #elif EFSW_PLATFORM == EFSW_PLATFORM_FSEVENTS |
| 19 | #include <efsw/FileWatcherFSEvents.hpp> | 19 | #include <efsw/FileWatcherFSEvents.hpp> |
| 20 | #define FILEWATCHER_IMPL FileWatcherFSEvents | 20 | #define FILEWATCHER_IMPL FileWatcherFSEvents |
| 21 | #define BACKEND_NAME "FSEvents" | 21 | #define BACKEND_NAME "FSEvents" |
| 22 | #else | 22 | #else |
| 23 | #define FILEWATCHER_IMPL FileWatcherGeneric | 23 | #define FILEWATCHER_IMPL FileWatcherGeneric |
| 24 | #define BACKEND_NAME "Generic" | 24 | #define BACKEND_NAME "Generic" |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | #include <efsw/Debug.hpp> | 27 | #include <efsw/Debug.hpp> |
| 28 | 28 | ||
| 29 | namespace efsw { | 29 | namespace efsw { |
| 30 | 30 | ||
| 31 | FileWatcher::FileWatcher() : mFollowSymlinks( false ), mOutOfScopeLinks( false ) { | 31 | FileWatcher::FileWatcher() : mFollowSymlinks( false ), mOutOfScopeLinks( false ) { |
| 32 | efDEBUG( "Using backend: %s\n", BACKEND_NAME ); | 32 | efDEBUG( "Using backend: %s\n", BACKEND_NAME ); |
| 33 | 33 | ||
| 34 | mImpl = new FILEWATCHER_IMPL( this ); | 34 | mImpl = new FILEWATCHER_IMPL( this ); |
| 35 | 35 | ||
| 36 | if ( !mImpl->initOK() ) { | 36 | if ( !mImpl->initOK() ) { |
| 37 | efSAFE_DELETE( mImpl ); | 37 | efSAFE_DELETE( mImpl ); |
| 38 | 38 | ||
| 39 | efDEBUG( "Falled back to backend: %s\n", BACKEND_NAME ); | 39 | efDEBUG( "Falled back to backend: %s\n", BACKEND_NAME ); |
| 40 | 40 | ||
| 41 | mImpl = new FileWatcherGeneric( this ); | 41 | mImpl = new FileWatcherGeneric( this ); |
| 42 | } | 42 | } |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | FileWatcher::FileWatcher( bool useGenericFileWatcher ) : | 45 | FileWatcher::FileWatcher( bool useGenericFileWatcher ) : |
| 46 | mFollowSymlinks( false ), mOutOfScopeLinks( false ) { | 46 | mFollowSymlinks( false ), mOutOfScopeLinks( false ) { |
| 47 | if ( useGenericFileWatcher ) { | 47 | if ( useGenericFileWatcher ) { |
| 48 | efDEBUG( "Using backend: Generic\n" ); | 48 | efDEBUG( "Using backend: Generic\n" ); |
| 49 | 49 | ||
| 50 | mImpl = new FileWatcherGeneric( this ); | 50 | mImpl = new FileWatcherGeneric( this ); |
| 51 | } else { | 51 | } else { |
| 52 | efDEBUG( "Using backend: %s\n", BACKEND_NAME ); | 52 | efDEBUG( "Using backend: %s\n", BACKEND_NAME ); |
| 53 | 53 | ||
| 54 | mImpl = new FILEWATCHER_IMPL( this ); | 54 | mImpl = new FILEWATCHER_IMPL( this ); |
| 55 | 55 | ||
| 56 | if ( !mImpl->initOK() ) { | 56 | if ( !mImpl->initOK() ) { |
| 57 | efSAFE_DELETE( mImpl ); | 57 | efSAFE_DELETE( mImpl ); |
| 58 | 58 | ||
| 59 | efDEBUG( "Falled back to backend: %s\n", BACKEND_NAME ); | 59 | efDEBUG( "Falled back to backend: %s\n", BACKEND_NAME ); |
| 60 | 60 | ||
| 61 | mImpl = new FileWatcherGeneric( this ); | 61 | mImpl = new FileWatcherGeneric( this ); |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | FileWatcher::~FileWatcher() { | 66 | FileWatcher::~FileWatcher() { |
| 67 | efSAFE_DELETE( mImpl ); | 67 | efSAFE_DELETE( mImpl ); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | WatchID FileWatcher::addWatch( const std::string& directory, FileWatchListener* watcher ) { | 70 | WatchID FileWatcher::addWatch( const std::string& directory, FileWatchListener* watcher ) { |
| 71 | if ( mImpl->mIsGeneric || !FileSystem::isRemoteFS( directory ) ) { | 71 | return addWatch( directory, watcher, false, {} ); |
| 72 | return mImpl->addWatch( directory, watcher, false ); | 72 | } |
| 73 | } else { | 73 | |
| 74 | return Errors::Log::createLastError( Errors::FileRemote, directory ); | 74 | WatchID FileWatcher::addWatch( const std::string& directory, FileWatchListener* watcher, |
| 75 | } | 75 | bool recursive ) { |
| 76 | } | 76 | return addWatch( directory, watcher, recursive, {} ); |
| 77 | 77 | } | |
| 78 | WatchID FileWatcher::addWatch( const std::string& directory, FileWatchListener* watcher, | 78 | |
| 79 | bool recursive ) { | 79 | WatchID FileWatcher::addWatch( const std::string& directory, FileWatchListener* watcher, |
| 80 | if ( mImpl->mIsGeneric || !FileSystem::isRemoteFS( directory ) ) { | 80 | bool recursive, const std::vector<WatcherOption>& options ) { |
| 81 | return mImpl->addWatch( directory, watcher, recursive ); | 81 | if ( mImpl->mIsGeneric || !FileSystem::isRemoteFS( directory ) ) { |
| 82 | } else { | 82 | return mImpl->addWatch( directory, watcher, recursive, options ); |
| 83 | return Errors::Log::createLastError( Errors::FileRemote, directory ); | 83 | } else { |
| 84 | } | 84 | return Errors::Log::createLastError( Errors::FileRemote, directory ); |
| 85 | } | 85 | } |
| 86 | 86 | } | |
| 87 | void FileWatcher::removeWatch( const std::string& directory ) { | 87 | |
| 88 | mImpl->removeWatch( directory ); | 88 | void FileWatcher::removeWatch( const std::string& directory ) { |
| 89 | } | 89 | mImpl->removeWatch( directory ); |
| 90 | 90 | } | |
| 91 | void FileWatcher::removeWatch( WatchID watchid ) { | 91 | |
| 92 | mImpl->removeWatch( watchid ); | 92 | void FileWatcher::removeWatch( WatchID watchid ) { |
| 93 | } | 93 | mImpl->removeWatch( watchid ); |
| 94 | 94 | } | |
| 95 | void FileWatcher::watch() { | 95 | |
| 96 | mImpl->watch(); | 96 | void FileWatcher::watch() { |
| 97 | } | 97 | mImpl->watch(); |
| 98 | 98 | } | |
| 99 | std::list<std::string> FileWatcher::directories() { | 99 | |
| 100 | return mImpl->directories(); | 100 | std::vector<std::string> FileWatcher::directories() { |
| 101 | } | 101 | return mImpl->directories(); |
| 102 | 102 | } | |
| 103 | void FileWatcher::followSymlinks( bool follow ) { | 103 | |
| 104 | mFollowSymlinks = follow; | 104 | void FileWatcher::followSymlinks( bool follow ) { |
| 105 | } | 105 | mFollowSymlinks = follow; |
| 106 | 106 | } | |
| 107 | const bool& FileWatcher::followSymlinks() const { | 107 | |
| 108 | return mFollowSymlinks; | 108 | const bool& FileWatcher::followSymlinks() const { |
| 109 | } | 109 | return mFollowSymlinks; |
| 110 | 110 | } | |
| 111 | void FileWatcher::allowOutOfScopeLinks( bool allow ) { | 111 | |
| 112 | mOutOfScopeLinks = allow; | 112 | void FileWatcher::allowOutOfScopeLinks( bool allow ) { |
| 113 | } | 113 | mOutOfScopeLinks = allow; |
| 114 | 114 | } | |
| 115 | const bool& FileWatcher::allowOutOfScopeLinks() const { | 115 | |
| 116 | return mOutOfScopeLinks; | 116 | const bool& FileWatcher::allowOutOfScopeLinks() const { |
| 117 | } | 117 | return mOutOfScopeLinks; |
| 118 | 118 | } | |
| 119 | } // namespace efsw | 119 | |
| 120 | } // namespace efsw | ||
