From 83a3c9fc8d90ddafe6fb2e752d57af161b081d83 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 12 Jan 2020 14:43:43 +1100 Subject: [PATCH] handle when fsnotify doesn't work --- pkg/gui/file_watching.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/gui/file_watching.go b/pkg/gui/file_watching.go index 7a56a1e81..3a9532116 100644 --- a/pkg/gui/file_watching.go +++ b/pkg/gui/file_watching.go @@ -19,13 +19,20 @@ type fileWatcher struct { Watcher *fsnotify.Watcher WatchedFilenames []string Log *logrus.Entry + Disabled bool } func NewFileWatcher(log *logrus.Entry) *fileWatcher { watcher, err := fsnotify.NewWatcher() + log.Error(err) + return &fileWatcher{ + Disabled: true, + } if err != nil { log.Error(err) - return nil + return &fileWatcher{ + Disabled: true, + } } return &fileWatcher{ @@ -66,6 +73,10 @@ func (w *fileWatcher) watchFilename(filename string) { } func (w *fileWatcher) addFilesToFileWatcher(files []*commands.File) error { + if w.Disabled { + return nil + } + if len(files) == 0 { return nil } @@ -105,7 +116,7 @@ func min(a int, b int) int { // TODO: consider watching the whole directory recursively (could be more expensive) func (gui *Gui) watchFilesForChanges() { gui.fileWatcher = NewFileWatcher(gui.Log) - if gui.fileWatcher == nil { + if gui.fileWatcher.Disabled { return } go func() {