]> go.fuhry.dev Git - fsnotify.git/commitdiff
BSD - Return errors during watch instead of sending over channel
authorChris Howey <chris@howey.me>
Thu, 3 May 2012 22:48:30 +0000 (17:48 -0500)
committerChris Howey <chris@howey.me>
Thu, 3 May 2012 22:48:30 +0000 (17:48 -0500)
fsnotify_bsd.go

index 2f5d7b4b1fc715f9c35a1f034ce2bea836ac01ca..de74e069aa2b925033d343222940ed82d3fb2a8e 100644 (file)
@@ -132,7 +132,10 @@ func (w *Watcher) addWatch(path string, flags uint32) error {
 
                w.finfo[watchfd] = fi
                if fi.IsDir() {
-                       w.watchDirectoryFiles(path)
+                       errdir := w.watchDirectoryFiles(path)
+                       if errdir != nil {
+                               return errdir
+                       }
                }
        }
        syscall.SetKevent(watchEntry, watchfd, syscall.EVFILT_VNODE, syscall.EV_ADD|syscall.EV_CLEAR)
@@ -242,11 +245,11 @@ func (w *Watcher) readEvents() {
        }
 }
 
-func (w *Watcher) watchDirectoryFiles(dirPath string) {
+func (w *Watcher) watchDirectoryFiles(dirPath string) error {
        // Get all files
        files, err := ioutil.ReadDir(dirPath)
        if err != nil {
-               w.Error <- err
+               return err
        }
 
        // Search for new files
@@ -256,10 +259,12 @@ func (w *Watcher) watchDirectoryFiles(dirPath string) {
                        // Watch file to mimic linux fsnotify
                        e := w.addWatch(filePath, NOTE_DELETE|NOTE_WRITE|NOTE_RENAME)
                        if e != nil {
-                               w.Error <- e
+                               return e
                        }
                }
        }
+
+       return nil
 }
 
 // sendDirectoryEvents searches the directory for newly created files