mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 11:44:51 +00:00
refactor again
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user