filter fs events for valid names. don't respond to chmod events

This commit is contained in:
sawka 2024-07-30 15:54:59 -07:00
parent fe708d1d37
commit 4025d2fa9a

View File

@ -10,6 +10,7 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"sync" "sync"
@ -245,7 +246,12 @@ func (w *Watcher) handleEvent(event fsnotify.Event) {
defer w.mutex.Unlock() defer w.mutex.Unlock()
fileName := filepath.ToSlash(event.Name) fileName := filepath.ToSlash(event.Name)
if event.Op == fsnotify.Chmod {
return
}
if !isValidSubSettingsFileName(fileName) {
return
}
if isInDirectory(fileName, termThemesDirAbsPath) { if isInDirectory(fileName, termThemesDirAbsPath) {
w.handleTermThemesEvent(event, fileName) w.handleTermThemesEvent(event, fileName)
} else if filepath.Base(fileName) == filepath.Base(settingsAbsPath) { } 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) { func (w *Watcher) handleTermThemesEvent(event fsnotify.Event, fileName string) {
settings, err := LoadFullSettings() settings, err := LoadFullSettings()
if err != nil { if err != nil {