Merge pull request #1025 from aledbf/fix-file-watch

Fix file watch
This commit is contained in:
Manuel Alejandro de Brito Fontes 2017-07-27 10:37:56 -04:00 committed by GitHub
commit b2064cb695
2 changed files with 6 additions and 5 deletions

View file

@ -19,6 +19,7 @@ package watch
import ( import (
"log" "log"
"path" "path"
"strings"
"gopkg.in/fsnotify.v1" "gopkg.in/fsnotify.v1"
) )
@ -42,7 +43,7 @@ func NewFileWatcher(file string, onEvent func()) (FileWatcher, error) {
} }
// Close ends the watch // Close ends the watch
func (f FileWatcher) Close() error { func (f *FileWatcher) Close() error {
return f.watcher.Close() return f.watcher.Close()
} }
@ -59,9 +60,9 @@ func (f *FileWatcher) watch() error {
for { for {
select { select {
case event := <-watcher.Events: case event := <-watcher.Events:
if event.Op&fsnotify.Write == fsnotify.Write || if (event.Op&fsnotify.Write == fsnotify.Write ||
event.Op&fsnotify.Create == fsnotify.Create && event.Op&fsnotify.Create == fsnotify.Create) &&
event.Name == file { strings.HasSuffix(event.Name, file) {
f.onEvent() f.onEvent()
} }
case err := <-watcher.Errors: case err := <-watcher.Errors:

View file

@ -26,7 +26,7 @@ import (
func prepareTimeout() chan bool { func prepareTimeout() chan bool {
timeoutChan := make(chan bool, 1) timeoutChan := make(chan bool, 1)
go func() { go func() {
time.Sleep(1 * time.Second) time.Sleep(500 * time.Millisecond)
timeoutChan <- true timeoutChan <- true
}() }()
return timeoutChan return timeoutChan