From 9c4905d89b50d82fdf68c5e92fc6b523c6458e7f Mon Sep 17 00:00:00 2001 From: lishiye19 <42347483+lishiye19@users.noreply.github.com> Date: Mon, 29 Sep 2025 16:30:30 +0800 Subject: [PATCH] Update watcher.go Safety judgment error --- watcher.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/watcher.go b/watcher.go index 4da4dfe..bc68603 100644 --- a/watcher.go +++ b/watcher.go @@ -511,10 +511,19 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo { if err != nil { if os.IsNotExist(err) { w.mu.Unlock() - if name == err.(*os.PathError).Path { - w.Error <- ErrWatchedFileDeleted - w.Remove(name) + pErr,ok:=err.(*os.PathError) + if !ok { + w.Error<-errors.New("error: err marshal to os.PathError failed.") + }else { + if name == pErr.Path { + w.Error <- ErrWatchedFileDeleted + w.RemoveRecursive(name) + } } + //if name == err.(*os.PathError).Path { + // w.Error <- ErrWatchedFileDeleted + // w.RemoveRecursive(name) + //} w.mu.Lock() } else { w.Error <- err