Skip to content

Commit d8b41ca

Browse files
committed
Fix retrieveFilelist for the instances where files are deleted in
between retrieving file names and stat during filepath.Walk
1 parent 593985f commit d8b41ca

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

watcher.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,11 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo {
495495
list, err = w.listRecursive(name)
496496
if err != nil {
497497
if os.IsNotExist(err) {
498-
w.Error <- ErrWatchedFileDeleted
499498
w.mu.Unlock()
500-
w.RemoveRecursive(err.(*os.PathError).Path)
499+
if name == err.(*os.PathError).Path {
500+
w.Error <- ErrWatchedFileDeleted
501+
w.RemoveRecursive(name)
502+
}
501503
w.mu.Lock()
502504
} else {
503505
w.Error <- err
@@ -507,9 +509,11 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo {
507509
list, err = w.list(name)
508510
if err != nil {
509511
if os.IsNotExist(err) {
510-
w.Error <- ErrWatchedFileDeleted
511512
w.mu.Unlock()
512-
w.Remove(err.(*os.PathError).Path)
513+
if name == err.(*os.PathError).Path {
514+
w.Error <- ErrWatchedFileDeleted
515+
w.Remove(name)
516+
}
513517
w.mu.Lock()
514518
} else {
515519
w.Error <- err

0 commit comments

Comments
 (0)