refactor again

This commit is contained in:
Dominic Breuker
2018-03-12 08:24:57 +01:00
parent 479923263d
commit f2783e95c6

View File

@@ -77,11 +77,7 @@ func (fs *FSWatcher) addWatchersToDir(dir string, depth int, errCh chan error) {
return return
} }
done, err := fs.handleNextWalkerResult(dirCh, walkErrCh) if done := fs.handleNextWalkerResult(dirCh, walkErrCh, errCh); done {
if err != nil {
errCh <- err
}
if done {
return return
} }
} }
@@ -91,19 +87,19 @@ func (fs *FSWatcher) maximumWatchersExceeded() bool {
return fs.maxWatchers > 0 && fs.i.NumWatchers() >= fs.maxWatchers return fs.maxWatchers > 0 && fs.i.NumWatchers() >= fs.maxWatchers
} }
func (fs *FSWatcher) handleNextWalkerResult(dirCh chan string, walkErrCh chan error) (bool, error) { func (fs *FSWatcher) handleNextWalkerResult(dirCh chan string, walkErrCh chan error, errCh chan error) bool {
select { select {
case err := <-walkErrCh: case err := <-walkErrCh:
return false, fmt.Errorf("adding inotify watchers: %v", err) errCh <- fmt.Errorf("adding inotify watchers: %v", err)
case dir, ok := <-dirCh: case dir, ok := <-dirCh:
if !ok { if !ok {
return true, nil // finished return true
} }
if err := fs.i.Watch(dir); err != nil { if err := fs.i.Watch(dir); err != nil {
return false, fmt.Errorf("Can't create watcher: %v", err) errCh <- fmt.Errorf("Can't create watcher: %v", err)
} }
} }
return false, nil return false
} }
func (fs *FSWatcher) Run() (chan struct{}, chan string, chan error) { func (fs *FSWatcher) Run() (chan struct{}, chan string, chan error) {