1
0
mirror of https://github.com/beego/bee.git synced 2024-12-25 14:50:51 +00:00

skip TMP files and gofmt events

This commit is contained in:
Unknown 2013-07-24 14:58:13 +08:00
parent 7e4fd3f528
commit 0feb778d4d

View File

@ -6,9 +6,9 @@ import (
"log" "log"
"os" "os"
"os/exec" "os/exec"
"strings"
"sync" "sync"
"time" "time"
"strings"
) )
var ( var (
@ -28,14 +28,21 @@ func NewWatcher(paths []string) {
select { select {
case e := <-watcher.Event: case e := <-watcher.Event:
isbuild := true 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. // if 500ms change many times, then ignore it.
// for liteide often gofmt code after save. // for liteide often gofmt code after save.
if t.Add(time.Millisecond * 500).After(time.Now()) { if t.Add(time.Millisecond * 500).After(time.Now()) {
fmt.Println("[SKIP]", e.String())
isbuild = false isbuild = false
} }
} }
eventTime[e.String()] = time.Now() eventTime[e.Name] = time.Now()
if isbuild { if isbuild {
fmt.Println(e) fmt.Println(e)
@ -95,7 +102,7 @@ func Restart(appname string) {
func Start(appname string) { func Start(appname string) {
fmt.Println("start", appname) fmt.Println("start", appname)
if strings.Index(appname, "./") == -1 { if strings.Index(appname, "./") == -1 {
appname = "./" + appname appname = "./" + appname
} }
@ -106,3 +113,11 @@ func Start(appname string) {
go cmd.Run() 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
}