Fixed multiple events on change

This commit is contained in:
alessio 2016-08-01 16:16:09 +02:00
parent 2358f76e65
commit d2a73eec94
1 changed files with 17 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import (
"log"
"strings"
"sync"
"time"
)
func InArray(str string, list []string) bool{
@ -52,29 +53,39 @@ func (h *Config) Watch() error{
}
watch := func(val Project){
watcher, _ = fsnotify.NewWatcher()
// run, bin, build
val.reload = time.Now().Truncate(time.Second)
for _, dir := range val.Watcher.Paths {
path, _ := os.Getwd()
current = val.Watcher
// add dir of project
if err := filepath.Walk(path + dir, walk); err != nil {
fmt.Println(err)
}
}
for {
select {
case event := <-watcher.Events:
if time.Now().Truncate(time.Second).After(val.reload) {
if event.Op & fsnotify.Chmod == fsnotify.Chmod {
continue
}
if _, err := os.Stat(event.Name); err == nil {
log.Println("event:", event)
// run, bin, build
val.reload = time.Now().Truncate(time.Second)
}
}
case err := <-watcher.Errors:
log.Println("error:", err)
}
}
wg.Done()
watcher.Close()
wg.Done()
}
// add to watcher