@@ -69,15 +69,17 @@ FileWatcherInotify::~FileWatcherInotify() {
69
69
}
70
70
71
71
WatchID FileWatcherInotify::addWatch ( const std::string& directory, FileWatchListener* watcher,
72
- bool recursive, const std::vector<WatcherOption>& ) {
72
+ bool recursive, const std::vector<WatcherOption>& options ) {
73
73
if ( !mInitOK )
74
74
return Errors::Log::createLastError ( Errors::Unspecified, directory );
75
75
Lock initLock ( mInitLock );
76
- return addWatch ( directory, watcher, recursive, NULL );
76
+ bool syntheticEvents = getOptionValue ( options, Options::LinuxProduceSyntheticEvents, 0 ) != 0 ;
77
+ return addWatch ( directory, watcher, recursive, syntheticEvents, NULL );
77
78
}
78
79
79
80
WatchID FileWatcherInotify::addWatch ( const std::string& directory, FileWatchListener* watcher,
80
- bool recursive, WatcherInotify* parent ) {
81
+ bool recursive, bool syntheticEvents,
82
+ WatcherInotify* parent, bool fromInternalEvent ) {
81
83
std::string dir ( directory );
82
84
83
85
FileSystem::dirAddSlashAtEnd ( dir );
@@ -160,7 +162,17 @@ WatchID FileWatcherInotify::addWatch( const std::string& directory, FileWatchLis
160
162
const FileInfo& cfi = it->second ;
161
163
162
164
if ( cfi.isDirectory () && cfi.isReadable () ) {
163
- addWatch ( cfi.Filepath , watcher, recursive, pWatch );
165
+ addWatch ( cfi.Filepath , watcher, recursive, syntheticEvents, pWatch );
166
+ }
167
+ }
168
+
169
+ if ( fromInternalEvent && parent != NULL && syntheticEvents ) {
170
+ for ( const auto & file : files ) {
171
+ if ( file.second .isRegularFile () ) {
172
+ pWatch->Listener ->handleFileAction (
173
+ pWatch->ID , pWatch->Directory ,
174
+ FileSystem::fileNameFromPath ( file.second .Filepath ), Actions::Add );
175
+ }
164
176
}
165
177
}
166
178
}
@@ -448,8 +460,9 @@ void FileWatcherInotify::checkForNewWatcher( Watcher* watch, std::string fpath )
448
460
}
449
461
450
462
if ( !found ) {
451
- addWatch ( fpath, watch->Listener , watch->Recursive ,
452
- static_cast <WatcherInotify*>( watch ) );
463
+ WatcherInotify* iWatch = static_cast <WatcherInotify*>( watch );
464
+ addWatch ( fpath, watch->Listener , watch->Recursive , iWatch->syntheticEvents ,
465
+ static_cast <WatcherInotify*>( watch ), true );
453
466
}
454
467
}
455
468
}
0 commit comments