From b81b32572586d7f15de9c37db5e8bc3bef80e747 Mon Sep 17 00:00:00 2001 From: lyt122 <2747177214@qq.com> Date: Mon, 15 Jul 2024 20:15:00 +0800 Subject: [PATCH] refactor codes --- plugins/pkg/file/fs.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/pkg/file/fs.go b/plugins/pkg/file/fs.go index 71c92e9d..2e52bf72 100644 --- a/plugins/pkg/file/fs.go +++ b/plugins/pkg/file/fs.go @@ -56,13 +56,15 @@ func (w *Watcher) AddFiles(files ...*File) error { w.mu.Lock() defer w.mu.Unlock() for _, file := range files { - if _, exists := w.files[file.Name]; !exists { - w.files[file.Name] = true - } - dir, err := filepath.Abs(file.Name) + absPath, err := filepath.Abs(file.Name) if err != nil { return err } + if _, exists := w.files[absPath]; !exists { + w.files[absPath] = true + } + + dir := filepath.Dir(absPath) if _, exists := w.dir[dir]; !exists { if err := w.watcher.Add(dir); err != nil { return err @@ -79,7 +81,7 @@ func (w *Watcher) Start(onChanged func()) { for { select { case event := <-w.watcher.Events: - if event.Op&fsnotify.Chmod == fsnotify.Chmod { + if event.Op.Has(fsnotify.Chmod) { continue } absPath, err := filepath.Abs(event.Name)