From 406658de13004ab9bbe7bdc850e4d191e838975b Mon Sep 17 00:00:00 2001 From: Morten Slaatten Berg Date: Thu, 21 Dec 2017 10:55:37 +0100 Subject: [PATCH 1/5] Trigger reload if event time is equal to or later than file modified time This covers the case when editing the same file several times, as event time and file modified time often has the same value when this code is reached. --- realize/projects.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realize/projects.go b/realize/projects.go index 3613764..984b32c 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -308,7 +308,7 @@ L: if fi.IsDir() { filepath.Walk(event.Name, p.walk) } else { - if event.Op != fsnotify.Write || (eventTime.Truncate(time.Millisecond).After(fi.ModTime().Truncate(time.Millisecond)) || event.Name != p.lastFile) { + if event.Op != fsnotify.Write || (!eventTime.Truncate(time.Millisecond).Before(fi.ModTime().Truncate(time.Millisecond)) || event.Name != p.lastFile) { // stop and restart close(p.stop) p.stop = make(chan bool) From 5929e65b9d230f5d0fcabc3a82a589b58f5c1627 Mon Sep 17 00:00:00 2001 From: asoseil Date: Wed, 27 Dec 2017 12:38:43 +0100 Subject: [PATCH 2/5] debug option --- realize/projects.go | 5 ++++- realize/settings.go | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/realize/projects.go b/realize/projects.go index 3613764..9e612f6 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -284,6 +284,9 @@ L: for { select { case event := <-p.watcher.Events(): + if p.parent.Settings.Debug { + log.Println("Event:", event, "File:", event.Name, "LastFile:", p.lastFile, "Time:", time.Second, "LastTime:", p.lastTime) + } if time.Now().Truncate(time.Second).After(p.lastTime) || event.Name != p.lastFile { // event time eventTime := time.Now() @@ -308,7 +311,7 @@ L: if fi.IsDir() { filepath.Walk(event.Name, p.walk) } else { - if event.Op != fsnotify.Write || (eventTime.Truncate(time.Millisecond).After(fi.ModTime().Truncate(time.Millisecond)) || event.Name != p.lastFile) { + if event.Op != fsnotify.Write || (!eventTime.Truncate(time.Millisecond).Before(fi.ModTime().Truncate(time.Millisecond)) || event.Name != p.lastFile) { // stop and restart close(p.stop) p.stop = make(chan bool) diff --git a/realize/settings.go b/realize/settings.go index d176a48..8a1ea8d 100644 --- a/realize/settings.go +++ b/realize/settings.go @@ -29,9 +29,10 @@ const ( // Settings defines a group of general settings and options type Settings struct { Files `yaml:"files,omitempty" json:"files,omitempty"` - Legacy Legacy `yaml:"legacy" json:"legacy"` - FileLimit int32 `yaml:"flimit,omitempty" json:"flimit,omitempty"` Recovery bool `yaml:"recovery,omitempty" json:"recovery,omitempty"` + Debug bool `yaml:"debug,omitempty" json:"debug,omitempty"` + FileLimit int32 `yaml:"flimit,omitempty" json:"flimit,omitempty"` + Legacy Legacy `yaml:"legacy" json:"legacy"` } // Legacy is used to force polling and set a custom interval From 00d1d21d925e610705b908142587bf49c8a24971 Mon Sep 17 00:00:00 2001 From: asoseil Date: Wed, 27 Dec 2017 14:14:14 +0100 Subject: [PATCH 3/5] skip dirs without go files --- realize/tools.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/realize/tools.go b/realize/tools.go index bbefa9c..ae0b36f 100644 --- a/realize/tools.go +++ b/realize/tools.go @@ -3,6 +3,7 @@ package realize import ( "bytes" "errors" + "io/ioutil" "os/exec" "path/filepath" "strings" @@ -95,6 +96,18 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) { if filepath.Ext(path) != "" { path = filepath.Dir(path) } + // check if there is at least one go file + matched := false + files, _ := ioutil.ReadDir(path) + for _, f := range files { + matched, _ = filepath.Match("*.go", f.Name()) + if matched { + break + } + } + if !matched { + return + } } else if !strings.HasSuffix(path, ".go") { return } From 40d1d0d88919560b7213c9b18aff5e0485eb5a8e Mon Sep 17 00:00:00 2001 From: asoseil Date: Wed, 27 Dec 2017 18:49:10 +0100 Subject: [PATCH 4/5] debug time fixed --- realize/projects.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realize/projects.go b/realize/projects.go index 9e612f6..b650ba7 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -285,7 +285,7 @@ L: select { case event := <-p.watcher.Events(): if p.parent.Settings.Debug { - log.Println("Event:", event, "File:", event.Name, "LastFile:", p.lastFile, "Time:", time.Second, "LastTime:", p.lastTime) + log.Println("Event:", event, "File:", event.Name, "LastFile:", p.lastFile, "Time:", time.Now(), "LastTime:", p.lastTime) } if time.Now().Truncate(time.Second).After(p.lastTime) || event.Name != p.lastFile { // event time From eb03861e9d356af1ef5008c310eaf8868b82742b Mon Sep 17 00:00:00 2001 From: asoseil Date: Fri, 29 Dec 2017 19:24:03 +0100 Subject: [PATCH 5/5] #144 fixed --- realize/projects.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/realize/projects.go b/realize/projects.go index b650ba7..6c9fd9a 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -288,8 +288,6 @@ L: log.Println("Event:", event, "File:", event.Name, "LastFile:", p.lastFile, "Time:", time.Now(), "LastTime:", p.lastTime) } if time.Now().Truncate(time.Second).After(p.lastTime) || event.Name != p.lastFile { - // event time - eventTime := time.Now() // switch event type switch event.Op { case fsnotify.Chmod: @@ -311,7 +309,7 @@ L: if fi.IsDir() { filepath.Walk(event.Name, p.walk) } else { - if event.Op != fsnotify.Write || (!eventTime.Truncate(time.Millisecond).Before(fi.ModTime().Truncate(time.Millisecond)) || event.Name != p.lastFile) { + if event.Op != fsnotify.Write || event.Name != p.lastFile { // stop and restart close(p.stop) p.stop = make(chan bool) @@ -366,7 +364,7 @@ func (p *Project) Validate(path string, fiche bool) bool { if err != nil { return false } - if fi.IsDir() || (!fi.IsDir() && fi.Size() > 0) { + if fi.Size() > 0 { return true } return false