From: Chris Howey Date: Thu, 3 May 2012 22:48:30 +0000 (-0500) Subject: BSD - Return errors during watch instead of sending over channel X-Git-Tag: v1.7.2~427 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=804525651f13fff6ead5405c20420571534f8bd8;p=fsnotify.git BSD - Return errors during watch instead of sending over channel --- diff --git a/fsnotify_bsd.go b/fsnotify_bsd.go index 2f5d7b4..de74e06 100644 --- a/fsnotify_bsd.go +++ b/fsnotify_bsd.go @@ -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