mirror of
https://github.com/rclone/rclone
synced 2025-01-03 03:46:24 +01:00
Ensure current directory hierarchy is being watched before returning from ChangeNotify().
This commit is contained in:
parent
df949abc7e
commit
17b5b7c368
@ -1269,20 +1269,23 @@ func (file *localOpenFile) Close() (err error) {
|
||||
//
|
||||
// Close the returned channel to stop being notified.
|
||||
func (f *Fs) ChangeNotify(ctx context.Context, notifyFunc func(string, fs.EntryType), pollIntervalChan <-chan time.Duration) {
|
||||
go func() {
|
||||
// Create new watcher
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
fs.Errorf(f, "Failed to create watcher for local filesystem")
|
||||
return
|
||||
}
|
||||
// Create new watcher, ensuring current directory hierarchy is being watched
|
||||
// before returning
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
fs.Errorf(f, "Failed to create watcher for local filesystem")
|
||||
return
|
||||
}
|
||||
f.watchPath(watcher, f.root)
|
||||
|
||||
go func(watcher *fsnotify.Watcher) {
|
||||
// Close watcher when done
|
||||
defer func() {
|
||||
err := watcher.Close()
|
||||
if err != nil {
|
||||
fs.Debugf(f, "Failed to close watcher: %v", err)
|
||||
}
|
||||
}()
|
||||
f.watchPath(watcher, f.root)
|
||||
|
||||
// Process events and errors
|
||||
for {
|
||||
@ -1336,7 +1339,7 @@ func (f *Fs) ChangeNotify(ctx context.Context, notifyFunc func(string, fs.EntryT
|
||||
fs.Debugf(f, "Error: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
}(watcher)
|
||||
}
|
||||
|
||||
// Watch a path, recursively
|
||||
|
Loading…
Reference in New Issue
Block a user