优化 types in
This commit is contained in:
parent
c8d8cfff72
commit
2eb994561d
10
fileboy.go
10
fileboy.go
@ -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 {
|
||||
|
@ -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"`
|
||||
|
5
util.go
5
util.go
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user