Skip to content

Cannot remove watch for deleted file #40

@cespare

Description

@cespare

Once a file is deleted, you cannot clean up watches for it. For instance, with fsnotify:

func (w *Watcher) Remove(name string) error {
    name = filepath.Clean(name)
    w.mu.Lock()
    defer w.mu.Unlock()
    watch, ok := w.watches[name]
    if !ok {
        return fmt.Errorf("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, name)
    return nil
}

The file is gone, so even though we find the watch in w.watches we return a syscall error and don't delete the entry from w.watches.

It seems that maybe we should delete from w.watches regardless, or at least if errno is EBADF. If this sounds good, I can make a PR (and try to figure out the appropriate change for other systems (at least darwin) as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions