From: Soge Zhang Date: Sun, 17 Aug 2014 16:28:19 +0000 (+0800) Subject: Make ./path and path equivalent. X-Git-Tag: v1.7.2~275 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=0daaab17cf06959186a466a5a3bc1fd1c640f20c;p=fsnotify.git Make ./path and path equivalent. Using filepath.Clean (BSD and Linux). --- diff --git a/fsnotify_bsd.go b/fsnotify_bsd.go index 5e02974..096fccf 100644 --- a/fsnotify_bsd.go +++ b/fsnotify_bsd.go @@ -114,6 +114,7 @@ func (w *Watcher) Close() error { // addWatch adds path to the watched file set. // The flags are interpreted as described in kevent(2). func (w *Watcher) addWatch(path string, flags uint32) error { + path = filepath.Clean(path) w.mu.Lock() if w.isClosed { w.mu.Unlock() @@ -216,6 +217,7 @@ func (w *Watcher) Add(name string) error { // Remove stops watching the the named file or directory (non-recursively). func (w *Watcher) Remove(name string) error { + name = filepath.Clean(name) w.wmut.Lock() watchfd, ok := w.watches[name] w.wmut.Unlock() diff --git a/fsnotify_linux.go b/fsnotify_linux.go index 51aca18..29c2868 100644 --- a/fsnotify_linux.go +++ b/fsnotify_linux.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "os" + "path/filepath" "strings" "sync" "syscall" @@ -97,6 +98,7 @@ func (w *Watcher) Close() error { // Add starts watching the named file or directory (non-recursively). func (w *Watcher) Add(name string) error { + name = filepath.Clean(name) if w.isClosed { return errors.New("inotify instance already closed") } @@ -125,6 +127,7 @@ func (w *Watcher) Add(name string) error { // Remove stops watching the the named file or directory (non-recursively). func (w *Watcher) Remove(name string) error { + name = filepath.Clean(name) w.mu.Lock() defer w.mu.Unlock() watch, ok := w.watches[name]