Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes regarding unwatching and rewatching a path #129

Merged
merged 14 commits into from
Oct 4, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
inotify: Handle removing of watches on non-existing paths
  • Loading branch information
imsodin committed Oct 4, 2017
commit 734d8904e3e9633a9197715711addbe28a14d967
12 changes: 10 additions & 2 deletions watcher_inotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (i *inotify) Unwatch(path string) (err error) {
return errors.New("notify: path " + path + " is already watched")
}
fd := atomic.LoadInt32(&i.fd)
if _, err = unix.InotifyRmWatch(int(fd), uint32(iwd)); err != nil {
if err = removeInotifyWatch(fd, iwd); err != nil {
return
}
i.Lock()
Expand All @@ -378,7 +378,7 @@ func (i *inotify) Close() (err error) {
return nil
}
for iwd := range i.m {
if _, e := unix.InotifyRmWatch(int(i.fd), uint32(iwd)); e != nil && err == nil {
if e := removeInotifyWatch(i.fd, iwd); e != nil && err == nil {
err = e
}
delete(i.m, iwd)
Expand All @@ -395,3 +395,11 @@ func (i *inotify) Close() (err error) {
}
return
}

// if path was removed, notify already removed the watch and returns EINVAL error
func removeInotifyWatch(fd int32, iwd int32) (err error) {
if _, err = unix.InotifyRmWatch(int(fd), uint32(iwd)); err != nil && err != unix.EINVAL {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return
}
return nil
}