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.
|
// Close the returned channel to stop being notified.
|
||||||
func (f *Fs) ChangeNotify(ctx context.Context, notifyFunc func(string, fs.EntryType), pollIntervalChan <-chan time.Duration) {
|
func (f *Fs) ChangeNotify(ctx context.Context, notifyFunc func(string, fs.EntryType), pollIntervalChan <-chan time.Duration) {
|
||||||
go func() {
|
// Create new watcher, ensuring current directory hierarchy is being watched
|
||||||
// Create new watcher
|
// before returning
|
||||||
watcher, err := fsnotify.NewWatcher()
|
watcher, err := fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Errorf(f, "Failed to create watcher for local filesystem")
|
fs.Errorf(f, "Failed to create watcher for local filesystem")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
f.watchPath(watcher, f.root)
|
||||||
|
|
||||||
|
go func(watcher *fsnotify.Watcher) {
|
||||||
|
// Close watcher when done
|
||||||
defer func() {
|
defer func() {
|
||||||
err := watcher.Close()
|
err := watcher.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Debugf(f, "Failed to close watcher: %v", err)
|
fs.Debugf(f, "Failed to close watcher: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
f.watchPath(watcher, f.root)
|
|
||||||
|
|
||||||
// Process events and errors
|
// Process events and errors
|
||||||
for {
|
for {
|
||||||
@ -1336,7 +1339,7 @@ func (f *Fs) ChangeNotify(ctx context.Context, notifyFunc func(string, fs.EntryT
|
|||||||
fs.Debugf(f, "Error: %s", err.Error())
|
fs.Debugf(f, "Error: %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}(watcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch a path, recursively
|
// Watch a path, recursively
|
||||||
|
Loading…
Reference in New Issue
Block a user