summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-01-12 14:43:43 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-01-12 14:46:23 +1100
commit83a3c9fc8d90ddafe6fb2e752d57af161b081d83 (patch)
tree56a3a82dc681d2e6130d7e134a0a80360cf0cd2b
parent5e95019b3f6881657e77b9aaae39dc9c378d969e (diff)
handle when fsnotify doesn't work
-rw-r--r--pkg/gui/file_watching.go15
1 files 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() {