]> go.fuhry.dev Git - fsnotify.git/commitdiff
Add/Remove accept a name rather than a path (same behavior).
authorNathan Youngman <git@nathany.com>
Sun, 22 Jun 2014 04:43:38 +0000 (22:43 -0600)
committerNathan Youngman <git@nathany.com>
Sun, 22 Jun 2014 04:43:38 +0000 (22:43 -0600)
fsnotify_bsd.go
fsnotify_linux.go
fsnotify_windows.go

index fb901ca499c82f2e403bf31cc6267e257f3e8682..8dd51e96278813c63c5bb76e98e87f7cc1629cf6 100644 (file)
@@ -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)
                }
        }
 
index fbec6da6745cf9026cffb0c8418a0629330f2d57..5e0d0f969a8ac4e64c7305f1b55a0b806db62451 100644 (file)
@@ -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
 }
 
index d0c7e25bcf3726d9a35734f523897aaa2cbe69ca..0d559c8b29eb67b51636275c2abb4cd2b91e3250 100644 (file)
@@ -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