1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-15 22:26:40 +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
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() {