add ignore suffix of the listener file

main
ehlxr 2020-11-10 17:13:49 +08:00
parent da54305188
commit 8dc1ebe6d9
6 changed files with 30 additions and 4 deletions

View File

@ -96,6 +96,11 @@ monitor:
types:
- .go
# 不监听文件的格式,此类文件更改不会执行 command 中的命令
# .DS_Store 后缀为 .DS_Store 的文件更改,不会执行 command 中的命令
types:
- .DS_Store
# 监听的事件类型,发生此类事件才执行 command 中的命令
# 没有该配置默认监听所有事件
# write 写入文件事件

View File

@ -93,6 +93,11 @@ monitor:
types:
- .go
# ignore the suffix of the listener file, which changes the file not to execute commands
# .DS_Store file changes suffixed with .go not execute commands
types:
- .DS_Store
# the type of event to listen to. Only when such an event occurs can the command in command be executed
# without this configuration, all events will be monitored by default
# write write file event

View File

@ -72,6 +72,7 @@ func parseConfig() {
}
// init map
cfg.Monitor.TypesMap = map[string]bool{}
cfg.Monitor.ExceptTypesMap = map[string]bool{}
cfg.Monitor.IncludeDirsMap = map[string]bool{}
cfg.Monitor.ExceptDirsMap = map[string]bool{}
cfg.Monitor.IncludeDirsRec = map[string]bool{}
@ -83,6 +84,9 @@ func parseConfig() {
for _, v := range cfg.Instruction {
cfg.InstructionMap[v] = true
}
for _, v := range cfg.Monitor.ExceptTypes {
cfg.Monitor.ExceptTypesMap[v] = true
}
log.Printf("%+v", cfg)
}
@ -92,8 +96,13 @@ func eventDispatcher(event fsnotify.Event) {
}
ext := path.Ext(event.Name)
if len(cfg.Monitor.Types) > 0 &&
!keyInMonitorTypesMap(".*", cfg) &&
!keyInMonitorTypesMap(ext, cfg) {
!keyInMonitorTypesMap(".*", cfg.Monitor.TypesMap) &&
!keyInMonitorTypesMap(ext, cfg.Monitor.TypesMap) {
return
}
if len(cfg.Monitor.ExceptTypes) > 0 &&
keyInMonitorTypesMap(ext, cfg.Monitor.ExceptTypesMap) {
return
}

View File

@ -6,11 +6,13 @@ type FileGirl struct {
}
Monitor struct {
Types []string `yaml:"types"`
ExceptTypes []string `yaml:"exceptTypes"`
IncludeDirs []string `yaml:"includeDirs"`
ExceptDirs []string `yaml:"exceptDirs"`
Events []string `yaml:"events"`
// convert to
TypesMap map[string]bool `yaml:"-"`
ExceptTypesMap map[string]bool `yaml:"-"`
IncludeDirsMap map[string]bool `yaml:"-"`
ExceptDirsMap map[string]bool `yaml:"-"`
DirsMap map[string]bool `yaml:"-"`

5
raw.go
View File

@ -32,6 +32,11 @@ monitor:
types:
- .go
# command
# .DS_Store .DS_Store command
types:
- .DS_Store
# command
#
# write

View File

@ -8,8 +8,8 @@ import (
"strings"
)
func keyInMonitorTypesMap(k string, cfg *FileGirl) bool {
_, ok := cfg.Monitor.TypesMap[k]
func keyInMonitorTypesMap(k string, maps map[string]bool) bool {
_, ok := maps[k]
return ok
}