mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
filter fs events for valid names. don't respond to chmod events
This commit is contained in:
parent
fe708d1d37
commit
4025d2fa9a
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user