mirror of
https://github.com/beego/bee.git
synced 2024-11-21 18:40:54 +00:00
Merge pull request #16 from Unknwon/master
skip TMP files and gofmt events
This commit is contained in:
commit
e6bb2e8d5e
21
watch.go
21
watch.go
@ -6,9 +6,9 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -28,14 +28,21 @@ func NewWatcher(paths []string) {
|
||||
select {
|
||||
case e := <-watcher.Event:
|
||||
isbuild := true
|
||||
if t, ok := eventTime[e.String()]; ok {
|
||||
|
||||
// Skip TMP files for Sublime Text.
|
||||
if checkTMPFile(e.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
if t, ok := eventTime[e.Name]; ok {
|
||||
// if 500ms change many times, then ignore it.
|
||||
// for liteide often gofmt code after save.
|
||||
if t.Add(time.Millisecond * 500).After(time.Now()) {
|
||||
fmt.Println("[SKIP]", e.String())
|
||||
isbuild = false
|
||||
}
|
||||
}
|
||||
eventTime[e.String()] = time.Now()
|
||||
eventTime[e.Name] = time.Now()
|
||||
|
||||
if isbuild {
|
||||
fmt.Println(e)
|
||||
@ -106,3 +113,11 @@ func Start(appname string) {
|
||||
|
||||
go cmd.Run()
|
||||
}
|
||||
|
||||
// checkTMPFile returns true if the event was for TMP files.
|
||||
func checkTMPFile(name string) bool {
|
||||
if strings.HasSuffix(strings.ToLower(name), ".tmp") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user