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
}
// 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]
}
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)
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)
}
}
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)
}
}
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
}
// 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")
}
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
}
}
// 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),
}
}
// 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