From cc159086503f18485413d79637564215c8821fdc Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 29 Jul 2022 20:28:22 +0200 Subject: [PATCH] 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 --- kqueue.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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() -- 2.50.1