diff --git a/core/pkg/watch/file_watcher.go b/core/pkg/watch/file_watcher.go index fe85c4cd0..0fea1a143 100644 --- a/core/pkg/watch/file_watcher.go +++ b/core/pkg/watch/file_watcher.go @@ -19,6 +19,7 @@ package watch import ( "log" "path" + "strings" "gopkg.in/fsnotify.v1" ) @@ -42,7 +43,7 @@ func NewFileWatcher(file string, onEvent func()) (FileWatcher, error) { } // Close ends the watch -func (f FileWatcher) Close() error { +func (f *FileWatcher) Close() error { return f.watcher.Close() } @@ -59,9 +60,9 @@ func (f *FileWatcher) watch() error { for { select { case event := <-watcher.Events: - if event.Op&fsnotify.Write == fsnotify.Write || - event.Op&fsnotify.Create == fsnotify.Create && - event.Name == file { + if (event.Op&fsnotify.Write == fsnotify.Write || + event.Op&fsnotify.Create == fsnotify.Create) && + strings.HasSuffix(event.Name, file) { f.onEvent() } case err := <-watcher.Errors: diff --git a/core/pkg/watch/file_watcher_test.go b/core/pkg/watch/file_watcher_test.go index 57b5c2c1c..5733cd07c 100644 --- a/core/pkg/watch/file_watcher_test.go +++ b/core/pkg/watch/file_watcher_test.go @@ -26,7 +26,7 @@ import ( func prepareTimeout() chan bool { timeoutChan := make(chan bool, 1) go func() { - time.Sleep(1 * time.Second) + time.Sleep(500 * time.Millisecond) timeoutChan <- true }() return timeoutChan