From 898a91c46cd348833d451465972afe0f0c12744a Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Sat, 21 Jun 2014 22:43:38 -0600 Subject: [PATCH] Add/Remove accept a name rather than a path (same behavior). --- fsnotify_bsd.go | 26 +++++++++++++------------- fsnotify_linux.go | 22 +++++++++++----------- fsnotify_windows.go | 12 ++++++------ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/fsnotify_bsd.go b/fsnotify_bsd.go index fb901ca..8dd51e9 100644 --- a/fsnotify_bsd.go +++ b/fsnotify_bsd.go @@ -104,8 +104,8 @@ func (w *Watcher) Close() error { w.pmut.Lock() ws := w.watches w.pmut.Unlock() - for path := range ws { - w.Remove(path) + for name := range ws { + w.Remove(name) } return nil @@ -207,20 +207,20 @@ func (w *Watcher) addWatch(path string, flags uint32) error { } // Add starts watching on the named file. -func (w *Watcher) Add(path string) error { +func (w *Watcher) Add(name string) error { w.ewmut.Lock() - w.externalWatches[path] = true + w.externalWatches[name] = true w.ewmut.Unlock() - return w.addWatch(path, sys_NOTE_ALLEVENTS) + return w.addWatch(name, sys_NOTE_ALLEVENTS) } // Remove stops watching on the named file. -func (w *Watcher) Remove(path string) error { +func (w *Watcher) Remove(name string) error { w.wmut.Lock() - watchfd, ok := w.watches[path] + watchfd, ok := w.watches[name] w.wmut.Unlock() if !ok { - return errors.New(fmt.Sprintf("can't remove non-existent kevent watch for: %s", path)) + return errors.New(fmt.Sprintf("can't remove non-existent kevent watch for: %s", name)) } var kbuf [1]syscall.Kevent_t watchEntry := &kbuf[0] @@ -234,10 +234,10 @@ func (w *Watcher) Remove(path string) error { } syscall.Close(watchfd) w.wmut.Lock() - delete(w.watches, path) + delete(w.watches, name) w.wmut.Unlock() w.enmut.Lock() - delete(w.enFlags, path) + delete(w.enFlags, name) w.enmut.Unlock() w.pmut.Lock() delete(w.paths, watchfd) @@ -251,7 +251,7 @@ func (w *Watcher) Remove(path string) error { w.pmut.Lock() for _, wpath := range w.paths { wdir, _ := filepath.Split(wpath) - if filepath.Clean(wdir) == filepath.Clean(path) { + if filepath.Clean(wdir) == filepath.Clean(name) { w.ewmut.Lock() if !w.externalWatches[wpath] { pathsToRemove = append(pathsToRemove, wpath) @@ -260,11 +260,11 @@ func (w *Watcher) Remove(path string) error { } } w.pmut.Unlock() - for _, p := range pathsToRemove { + for _, name := range pathsToRemove { // Since these are internal, not much sense in propagating error // to the user, as that will just confuse them with an error about // a path they did not explicitly watch themselves. - w.Remove(p) + w.Remove(name) } } diff --git a/fsnotify_linux.go b/fsnotify_linux.go index fbec6da..5e0d0f9 100644 --- a/fsnotify_linux.go +++ b/fsnotify_linux.go @@ -85,8 +85,8 @@ func (w *Watcher) Close() error { w.isClosed = true // Remove all watches - for path := range w.watches { - w.Remove(path) + for name := range w.watches { + w.Remove(name) } // Send "quit" message to the reader goroutine @@ -96,7 +96,7 @@ func (w *Watcher) Close() error { } // Add starts watching on the named file. -func (w *Watcher) Add(path string) error { +func (w *Watcher) Add(name string) error { if w.isClosed { return errors.New("inotify instance already closed") } @@ -104,38 +104,38 @@ func (w *Watcher) Add(path string) error { var flags uint32 = sys_AGNOSTIC_EVENTS w.mu.Lock() - watchEntry, found := w.watches[path] + watchEntry, found := w.watches[name] w.mu.Unlock() if found { watchEntry.flags |= flags flags |= syscall.IN_MASK_ADD } - wd, errno := syscall.InotifyAddWatch(w.fd, path, flags) + wd, errno := syscall.InotifyAddWatch(w.fd, name, flags) if wd == -1 { return errno } w.mu.Lock() - w.watches[path] = &watch{wd: uint32(wd), flags: flags} - w.paths[wd] = path + w.watches[name] = &watch{wd: uint32(wd), flags: flags} + w.paths[wd] = name w.mu.Unlock() return nil } // Remove stops watching on the named file. -func (w *Watcher) Remove(path string) error { +func (w *Watcher) Remove(name string) error { w.mu.Lock() defer w.mu.Unlock() - watch, ok := w.watches[path] + watch, ok := w.watches[name] if !ok { - return errors.New(fmt.Sprintf("can't remove non-existent inotify watch for: %s", path)) + return errors.New(fmt.Sprintf("can't remove non-existent inotify watch for: %s", name)) } success, errno := syscall.InotifyRmWatch(w.fd, watch.wd) if success == -1 { return os.NewSyscallError("inotify_rm_watch", errno) } - delete(w.watches, path) + delete(w.watches, name) return nil } diff --git a/fsnotify_windows.go b/fsnotify_windows.go index d0c7e25..0d559c8 100644 --- a/fsnotify_windows.go +++ b/fsnotify_windows.go @@ -144,13 +144,13 @@ func (w *Watcher) Close() error { } // AddWatch adds path to the watched file set. -func (w *Watcher) AddWatch(path string, flags uint32) error { +func (w *Watcher) AddWatch(name string, flags uint32) error { if w.isClosed { return errors.New("watcher already closed") } in := &input{ op: opAddWatch, - path: filepath.Clean(path), + path: filepath.Clean(name), flags: flags, reply: make(chan error), } @@ -162,15 +162,15 @@ func (w *Watcher) AddWatch(path string, flags uint32) error { } // Add starts watching on the named file. -func (w *Watcher) Add(path string) error { - return w.AddWatch(path, sys_FS_ALL_EVENTS) +func (w *Watcher) Add(name string) error { + return w.AddWatch(name, sys_FS_ALL_EVENTS) } // Remove stops watching on the named file. -func (w *Watcher) Remove(path string) error { +func (w *Watcher) Remove(name string) error { in := &input{ op: opRemoveWatch, - path: filepath.Clean(path), + path: filepath.Clean(name), reply: make(chan error), } w.input <- in -- 2.50.1