优化 path(break change)

master
dengsgo 2019-04-04 10:46:52 +08:00
parent 5c31d76fac
commit 758bd1e409
3 changed files with 6 additions and 10 deletions

View File

@ -52,7 +52,6 @@ func parseConfig() {
if cfg.Core.Version > Version {
log.Panicln(PreError, "current fileboy support max version : ", Version)
}
cfg.Monitor.RootWatch = false
// init map
cfg.Monitor.TypesMap = map[string]bool{}
cfg.Monitor.IncludeDirsMap = map[string]bool{}
@ -71,17 +70,13 @@ func eventDispatcher(event fsnotify.Event) {
!keyInMonitorTypesMap(ext, cfg) {
return
}
fileName := relativePath(projectFolder, event.Name)
if !cfg.Monitor.RootWatch && fileName != "filegirl.yaml" {
return
}
switch event.Op {
case
fsnotify.Write,
fsnotify.Rename:
log.Println("EVENT", event.Op.String(), ":", event.Name)
taskMan.Put(&changedFile{
Name: fileName,
Name: relativePath(projectFolder, event.Name),
Changed: time.Now().UnixNano(),
Ext: ext,
})
@ -104,7 +99,6 @@ func addWatcher() {
log.Fatalln(PreError, "dirs must be relative paths ! err path:", dir)
}
if darr[0] == "." {
cfg.Monitor.RootWatch = true
if len(darr) == 2 && darr[1] == "*" {
// The highest priority
dirsMap = map[string]bool{

View File

@ -8,8 +8,6 @@ type FileGirl struct {
Types []string `yaml:"types"`
IncludeDirs []string `yaml:"includeDirs"`
ExceptDirs []string `yaml:"exceptDirs"`
// project root watcher flag
RootWatch bool `yaml:"-"`
// convert to
TypesMap map[string]bool `yaml:"-"`
IncludeDirsMap map[string]bool `yaml:"-"`

View File

@ -55,5 +55,9 @@ func listFile(folder string, fun func(string)) {
}
func relativePath(folder, p string) string {
return strings.TrimPrefix(p, folder)
s := strings.ReplaceAll(strings.TrimPrefix(p, folder), "\\", "/")
if strings.HasPrefix(s, "/") && len(s) > 1 {
s = s[1:]
}
return s
}