fixed slash method

This commit is contained in:
alessio 2016-08-16 09:35:07 +02:00
parent 7ea79c5c2e
commit 85157bd943

View File

@ -25,9 +25,7 @@ func (h *Config) Watch() error {
// loop projects // loop projects
wg.Add(len(h.Projects)) wg.Add(len(h.Projects))
for k := range h.Projects { for k := range h.Projects {
if !slash(string(h.Projects[k].Path[0])) { _, h.Projects[k].Path = slash(h.Projects[k].Path)
h.Projects[k].Path = "/" + h.Projects[k].Path
}
go h.Projects[k].Watching() go h.Projects[k].Watching()
} }
wg.Wait() wg.Wait()
@ -48,8 +46,8 @@ func (p *Project) Watching() {
}() }()
walk := func(path string, info os.FileInfo, err error) error { walk := func(path string, info os.FileInfo, err error) error {
if !Ignore(path, p.Watcher.Ignore) { if !ignore(path, p.Watcher.Ignore) {
if (info.IsDir() && len(filepath.Ext(path)) == 0 && !strings.Contains(path, "/.")) || (InArray(filepath.Ext(path), p.Watcher.Exts)) { if (info.IsDir() && len(filepath.Ext(path)) == 0 && !strings.Contains(path, "/.")) || (inArray(filepath.Ext(path), p.Watcher.Exts)) {
if p.Watcher.Preview { if p.Watcher.Preview {
fmt.Println(p.Name + ": \t" + path) fmt.Println(p.Name + ": \t" + path)
} }
@ -68,17 +66,16 @@ func (p *Project) Watching() {
Fail(p.Name + ": \t" + base + p.Path + dir + p.Main + " doesn't exist. Main is required") Fail(p.Name + ": \t" + base + p.Path + dir + p.Main + " doesn't exist. Main is required")
return return
} }
// check paths existence
if slash(dir) { base = base + p.Path
base = base + p.Path if check, _ := slash(dir); check != true && len(dir) >= 1 {
}else{
base = base + p.Path + dir base = base + p.Path + dir
} }
if _, err := os.Stat(base); err == nil { if _, err := os.Stat(base); err == nil {
if err := filepath.Walk(base, walk); err != nil { if err := filepath.Walk(base, walk); err != nil {
Fail(err.Error()) Fail(err.Error())
} }
if slash(dir) { if check, _ := slash(dir); check == true && len(dir) <= 1 {
break break
} }
} else { } else {
@ -155,7 +152,7 @@ func (p *Project) run(channel chan bool) {
return return
} }
func InArray(str string, list []string) bool { func inArray(str string, list []string) bool {
for _, v := range list { for _, v := range list {
if v == str { if v == str {
return true return true
@ -164,12 +161,10 @@ func InArray(str string, list []string) bool {
return false return false
} }
func Ignore(str string, list []string) bool { func ignore(str string, list []string) bool {
base, _ := os.Getwd() base, _ := os.Getwd()
for _, v := range list { for _, v := range list {
if !slash(v) { _, v = slash(v)
v = "/" +v
}
if strings.Contains(str, base + v) { if strings.Contains(str, base + v) {
return true return true
} }
@ -177,9 +172,9 @@ func Ignore(str string, list []string) bool {
return false return false
} }
func slash(str string) bool{ func slash(str string) (bool, string){
if string(str[0]) == "/" { if string(str[0]) == "/" {
return true return true, str
} }
return false return false, "/"+str
} }