decreased complexity watch
This commit is contained in:
parent
7bedd4c32a
commit
5002abf479
24
notify.go
24
notify.go
|
@ -227,17 +227,12 @@ 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
|
||||||
default:
|
case err != nil:
|
||||||
}
|
|
||||||
|
|
||||||
fi, err := os.Stat(f.Name())
|
|
||||||
if err != nil {
|
|
||||||
// if we got an error here and lastFi is not set, we can presume that nothing has changed
|
|
||||||
// This should be safe since before `watch()` is called, a stat is performed, there is any error `watch` is not called
|
|
||||||
if lastFi == nil {
|
if lastFi == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -254,26 +249,17 @@ func (w *filePoller) watch(f *os.File, lastFi os.FileInfo, chClose chan struct{}
|
||||||
if err := w.sendErr(err, chClose); err != nil {
|
if err := w.sendErr(err, chClose); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
continue
|
case lastFi == nil:
|
||||||
}
|
|
||||||
|
|
||||||
if 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
|
||||||
}
|
}
|
||||||
lastFi = fi
|
lastFi = fi
|
||||||
continue
|
case fi.Mode() != lastFi.Mode():
|
||||||
}
|
|
||||||
|
|
||||||
if fi.Mode() != lastFi.Mode() {
|
|
||||||
if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Chmod, Name: f.Name()}, chClose); err != nil {
|
if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Chmod, Name: f.Name()}, chClose); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastFi = fi
|
lastFi = fi
|
||||||
continue
|
case fi.ModTime() != lastFi.ModTime() || fi.Size() != lastFi.Size():
|
||||||
}
|
|
||||||
|
|
||||||
if fi.ModTime() != lastFi.ModTime() || fi.Size() != lastFi.Size() {
|
|
||||||
if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Write, Name: f.Name()}, chClose); err != nil {
|
if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Write, Name: f.Name()}, chClose); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue