Skip to content
Merged
Changes from all commits
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
18 changes: 18 additions & 0 deletions backend_inotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ func (w *inotify) AddWith(path string, opts ...addOpt) error {
w.sendEvent(Event{Name: root, Op: Create})
}

// If there's a dir for which we don't have read permissions,
// skip it silently. If it's the root directory itself, return an error.
_, infoErr := d.Info()
if infoErr != nil && errors.Is(infoErr, os.ErrPermission) {
if root == path {
return fmt.Errorf("fsnotify: not a readable directory: %q", path)
}

return filepath.SkipDir // Skip this directory silently.
}

wf := flagRecurse
if root == path {
wf |= flagByUser
Expand Down Expand Up @@ -532,6 +543,13 @@ func (w *inotify) handleEvent(inEvent *unix.InotifyEvent, buf *[65536]byte, offs
ev = w.newEvent(curDir, unix.IN_CREATE, 0)
}

// If there's a dir for which we don't have read permissions,
// skip it silently. If it's the root directory itself, return an error.
_, infoErr := d.Info()
if infoErr != nil && errors.Is(infoErr, os.ErrPermission) {
return filepath.SkipDir // Skip this directory silently.
}

if d.IsDir() {
return w.register(curDir, watch.flags, flagRecurse)
}
Expand Down
Loading