优化 types in

master
dengsgo 2019-04-01 15:32:27 +08:00
parent c8d8cfff72
commit 2eb994561d
3 changed files with 16 additions and 6 deletions

View File

@ -49,15 +49,19 @@ func parseConfig() {
if cfg.Core.Version > Version {
log.Panicln(PreError, "current fileboy support max version : ", Version)
}
// types convert map
cfg.Monitor.TypesMap = map[string]bool{}
for _, v := range cfg.Monitor.Types {
cfg.Monitor.TypesMap[v] = true
}
log.Println(cfg)
}
func eventDispatcher(event fsnotify.Event) {
ext := path.Ext(event.Name)
if len(cfg.Monitor.Types) > 0 &&
cfg.Monitor.Types[0] != ".*" &&
!inStringArray(ext, cfg.Monitor.Types) {
//log.Println(ext, cfg.Monitor.Types, inStringArray(ext, cfg.Monitor.Types))
!keyInMonitorTypesMap(".*", cfg) &&
!keyInMonitorTypesMap(ext, cfg) {
return
}
switch event.Op {

View File

@ -5,9 +5,10 @@ type FileGirl struct {
Version int `yaml:"version"`
}
Monitor struct {
Types []string `yaml:"types"`
IncludeDirs []string `yaml:"includeDirs"`
ExceptDirs []string `yaml:"exceptDirs"`
Types []string `yaml:"types"`
TypesMap map[string]bool `yaml:"-"`
IncludeDirs []string `yaml:"includeDirs"`
ExceptDirs []string `yaml:"exceptDirs"`
}
Command struct {
Exec []string `yaml:"exec"`

View File

@ -15,6 +15,11 @@ func inStringArray(value string, arr []string) bool {
return false
}
func keyInMonitorTypesMap(k string, cfg *FileGirl) bool {
_, ok := cfg.Monitor.TypesMap[k]
return ok
}
func cmdParse2Array(s string, cf *changedFile) []string {
a := strings.Split(s, " ")
r := make([]string, 0)