diff --git a/pkg/wconfig/filewatcher.go b/pkg/wconfig/filewatcher.go index fe9dcbb6..785664a3 100644 --- a/pkg/wconfig/filewatcher.go +++ b/pkg/wconfig/filewatcher.go @@ -10,6 +10,7 @@ import ( "log" "os" "path/filepath" + "regexp" "strings" "sync" @@ -245,7 +246,12 @@ func (w *Watcher) handleEvent(event fsnotify.Event) { defer w.mutex.Unlock() fileName := filepath.ToSlash(event.Name) - + if event.Op == fsnotify.Chmod { + return + } + if !isValidSubSettingsFileName(fileName) { + return + } if isInDirectory(fileName, termThemesDirAbsPath) { w.handleTermThemesEvent(event, fileName) } else if filepath.Base(fileName) == filepath.Base(settingsAbsPath) { @@ -253,6 +259,16 @@ func (w *Watcher) handleEvent(event fsnotify.Event) { } } +var validFileRe = regexp.MustCompile(`^[a-zA-Z0-9_@.-]+\.json$`) + +func isValidSubSettingsFileName(fileName string) bool { + if filepath.Ext(fileName) != ".json" { + return false + } + baseName := filepath.Base(fileName) + return validFileRe.MatchString(baseName) +} + func (w *Watcher) handleTermThemesEvent(event fsnotify.Event, fileName string) { settings, err := LoadFullSettings() if err != nil {