From 8dc1ebe6d9c509db20539eb1192479e4f2e47b9a Mon Sep 17 00:00:00 2001 From: ehlxr Date: Tue, 10 Nov 2020 17:13:49 +0800 Subject: [PATCH] add ignore suffix of the listener file --- README.md | 5 +++++ README_EN.md | 5 +++++ fileboy.go | 13 +++++++++++-- filegirl.go | 2 ++ raw.go | 5 +++++ util.go | 4 ++-- 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e2b023c..48aa5b5 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,11 @@ monitor: # .* 所有的文件更改都会执行 command 中的命令 types: - .go + + # 不监听文件的格式,此类文件更改不会执行 command 中的命令 + # .DS_Store 后缀为 .DS_Store 的文件更改,不会执行 command 中的命令 + types: + - .DS_Store # 监听的事件类型,发生此类事件才执行 command 中的命令 # 没有该配置默认监听所有事件 diff --git a/README_EN.md b/README_EN.md index badb27f..68c7737 100644 --- a/README_EN.md +++ b/README_EN.md @@ -92,6 +92,11 @@ monitor: # .* all file changes execute commands in the command 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 diff --git a/fileboy.go b/fileboy.go index bb57f5c..85f0af2 100644 --- a/fileboy.go +++ b/fileboy.go @@ -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 } diff --git a/filegirl.go b/filegirl.go index f20fd39..e90b138 100644 --- a/filegirl.go +++ b/filegirl.go @@ -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:"-"` diff --git a/raw.go b/raw.go index 60c6d22..40d4a95 100644 --- a/raw.go +++ b/raw.go @@ -31,6 +31,11 @@ monitor: # .* 所有的文件更改都会执行 command 中的命令 types: - .go + + # 不监听文件的格式,此类文件更改不会执行 command 中的命令 + # .DS_Store 后缀为 .DS_Store 的文件更改,不会执行 command 中的命令 + types: + - .DS_Store # 监听的事件类型,发生此类事件才执行 command 中的命令 # 没有该配置默认监听所有事件 diff --git a/util.go b/util.go index 6649d3d..cfe5d00 100644 --- a/util.go +++ b/util.go @@ -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 }