Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file watch #1025

Merged
merged 1 commit into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions core/pkg/watch/file_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package watch
import (
"log"
"path"
"strings"

"gopkg.in/fsnotify.v1"
)
Expand All @@ -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()
}

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion core/pkg/watch/file_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down