1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-17 22:32:58 +02:00

handle when fsnotify doesn't work

This commit is contained in:
Jesse Duffield 2020-01-12 14:43:43 +11:00
parent 5e95019b3f
commit 83a3c9fc8d

View File

@ -19,13 +19,20 @@ type fileWatcher struct {
Watcher *fsnotify.Watcher Watcher *fsnotify.Watcher
WatchedFilenames []string WatchedFilenames []string
Log *logrus.Entry Log *logrus.Entry
Disabled bool
} }
func NewFileWatcher(log *logrus.Entry) *fileWatcher { func NewFileWatcher(log *logrus.Entry) *fileWatcher {
watcher, err := fsnotify.NewWatcher() watcher, err := fsnotify.NewWatcher()
log.Error(err)
return &fileWatcher{
Disabled: true,
}
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil return &fileWatcher{
Disabled: true,
}
} }
return &fileWatcher{ return &fileWatcher{
@ -66,6 +73,10 @@ func (w *fileWatcher) watchFilename(filename string) {
} }
func (w *fileWatcher) addFilesToFileWatcher(files []*commands.File) error { func (w *fileWatcher) addFilesToFileWatcher(files []*commands.File) error {
if w.Disabled {
return nil
}
if len(files) == 0 { if len(files) == 0 {
return nil return nil
} }
@ -105,7 +116,7 @@ func min(a int, b int) int {
// TODO: consider watching the whole directory recursively (could be more expensive) // TODO: consider watching the whole directory recursively (could be more expensive)
func (gui *Gui) watchFilesForChanges() { func (gui *Gui) watchFilesForChanges() {
gui.fileWatcher = NewFileWatcher(gui.Log) gui.fileWatcher = NewFileWatcher(gui.Log)
if gui.fileWatcher == nil { if gui.fileWatcher.Disabled {
return return
} }
go func() { go func() {