From: Martin Tournoij Date: Fri, 29 Jul 2022 18:28:22 +0000 (+0200) Subject: kqueue: better error if watching a file fails (#471) X-Git-Tag: v1.7.2~100 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=cc159086503f18485413d79637564215c8821fdc;p=fsnotify.git kqueue: better error if watching a file fails (#471) kqueue requires opening a file descriptor for every file; so we read the directory and do that. If this failed the error was quite unclear; for example: "/tmp/fsnotify_permission_denied/": permission denied This puts the filepath in there: "/tmp/fsnotify_permission_denied/": "/tmp/fsnotify_permission_denied/test2.log": permission denied Fixes #270 --- diff --git a/kqueue.go b/kqueue.go index 87c25b0..5247f7d 100644 --- a/kqueue.go +++ b/kqueue.go @@ -237,7 +237,7 @@ func (w *Watcher) addWatch(name string, flags uint32) (string, error) { } } - watchfd, err = unix.Open(name, openMode, 0700) + watchfd, err = unix.Open(name, openMode, 0) if watchfd == -1 { return "", err } @@ -429,7 +429,7 @@ func (w *Watcher) watchDirectoryFiles(dirPath string) error { filePath := filepath.Join(dirPath, fileInfo.Name()) filePath, err = w.internalWatch(filePath, fileInfo) if err != nil { - return err + return fmt.Errorf("%q: %w", filepath.Join(dirPath, fileInfo.Name()), err) } w.mu.Lock()