From d8b41ca2397a9b5cfc26adb10edbbcde40187a87 Mon Sep 17 00:00:00 2001 From: Benjamin Radovsky Date: Tue, 15 Jan 2019 11:31:47 +1100 Subject: [PATCH] Fix retrieveFilelist for the instances where files are deleted in between retrieving file names and stat during filepath.Walk --- watcher.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/watcher.go b/watcher.go index effac1d..ecb2fcd 100644 --- a/watcher.go +++ b/watcher.go @@ -495,9 +495,11 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo { list, err = w.listRecursive(name) if err != nil { if os.IsNotExist(err) { - w.Error <- ErrWatchedFileDeleted w.mu.Unlock() - w.RemoveRecursive(err.(*os.PathError).Path) + if name == err.(*os.PathError).Path { + w.Error <- ErrWatchedFileDeleted + w.RemoveRecursive(name) + } w.mu.Lock() } else { w.Error <- err @@ -507,9 +509,11 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo { list, err = w.list(name) if err != nil { if os.IsNotExist(err) { - w.Error <- ErrWatchedFileDeleted w.mu.Unlock() - w.Remove(err.(*os.PathError).Path) + if name == err.(*os.PathError).Path { + w.Error <- ErrWatchedFileDeleted + w.Remove(name) + } w.mu.Lock() } else { w.Error <- err