decreased complexity watch
This commit is contained in:
parent
5002abf479
commit
b98f93706e
18
notify.go
18
notify.go
|
@ -227,15 +227,16 @@ func (w *filePoller) watch(f *os.File, lastFi os.FileInfo, chClose chan struct{}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
for {
|
for {
|
||||||
time.Sleep(w.interval)
|
time.Sleep(w.interval)
|
||||||
fi, err := os.Stat(f.Name())
|
|
||||||
select {
|
select {
|
||||||
case <-chClose:
|
case <-chClose:
|
||||||
logrus.Debugf("watch for %s closed", f.Name())
|
logrus.Debugf("watch for %s closed", f.Name())
|
||||||
return
|
return
|
||||||
case err != nil:
|
default:
|
||||||
if lastFi == nil {
|
}
|
||||||
continue
|
|
||||||
}
|
fi, err := os.Stat(f.Name())
|
||||||
|
switch {
|
||||||
|
case err != nil && lastFi != nil:
|
||||||
// If it doesn't exist at this point, it must have been removed
|
// If it doesn't exist at this point, it must have been removed
|
||||||
// no need to send the error here since this is a valid operation
|
// no need to send the error here since this is a valid operation
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
@ -243,12 +244,10 @@ func (w *filePoller) watch(f *os.File, lastFi os.FileInfo, chClose chan struct{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastFi = nil
|
lastFi = nil
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
// at this point, send the error
|
// at this point, send the error
|
||||||
if err := w.sendErr(err, chClose); err != nil {
|
w.sendErr(err, chClose)
|
||||||
return
|
return
|
||||||
}
|
|
||||||
case lastFi == nil:
|
case lastFi == nil:
|
||||||
if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Create, Name: f.Name()}, chClose); err != nil {
|
if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Create, Name: f.Name()}, chClose); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -264,7 +263,6 @@ func (w *filePoller) watch(f *os.File, lastFi os.FileInfo, chClose chan struct{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastFi = fi
|
lastFi = fi
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue