From 0daaab17cf06959186a466a5a3bc1fd1c640f20c Mon Sep 17 00:00:00 2001 From: Soge Zhang Date: Mon, 18 Aug 2014 00:28:19 +0800 Subject: [PATCH] Make ./path and path equivalent. Using filepath.Clean (BSD and Linux). --- fsnotify_bsd.go | 2 ++ fsnotify_linux.go | 3 +++ 2 files changed, 5 insertions(+) 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] -- 2.50.1