]> go.fuhry.dev Git - fsnotify.git/commitdiff
kqueue: better error if watching a file fails (#471)
authorMartin Tournoij <martin@arp242.net>
Fri, 29 Jul 2022 18:28:22 +0000 (20:28 +0200)
committerGitHub <noreply@github.com>
Fri, 29 Jul 2022 18:28:22 +0000 (20:28 +0200)
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

index 87c25b062f42b59bc109ba53c65491b51174816d..5247f7dcf0386ba7f675904d4255363a10eba375 100644 (file)
--- 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()