diff --git a/cmd/commands/run/watch.go b/cmd/commands/run/watch.go index 7fb2a81..825b7b9 100644 --- a/cmd/commands/run/watch.go +++ b/cmd/commands/run/watch.go @@ -71,7 +71,7 @@ func NewWatcher(paths []string, files []string, isgenerate bool) { continue } - mt := getFileModTime(e.Name) + mt := utils.GetFileModTime(e.Name) if t := eventTime[e.Name]; mt == t { beeLogger.Log.Hintf(colors.Bold("Skipping: ")+"%s", e.String()) isBuild = false @@ -104,25 +104,6 @@ func NewWatcher(paths []string, files []string, isgenerate bool) { } } -// getFileModTime returns unix timestamp of `os.File.ModTime` for the given path. -func getFileModTime(path string) int64 { - path = strings.Replace(path, "\\", "/", -1) - f, err := os.Open(path) - if err != nil { - beeLogger.Log.Errorf("Failed to open file on '%s': %s", path, err) - return time.Now().Unix() - } - defer f.Close() - - fi, err := f.Stat() - if err != nil { - beeLogger.Log.Errorf("Failed to get file stats: %s", err) - return time.Now().Unix() - } - - return fi.ModTime().Unix() -} - // AutoBuild builds the specified set of files func AutoBuild(files []string, isgenerate bool) { state.Lock() diff --git a/utils/utils.go b/utils/utils.go index 5224c1b..b5bfa62 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -26,6 +26,7 @@ import ( "runtime" "strings" "text/template" + "time" "unicode" beeLogger "github.com/beego/bee/logger" @@ -67,7 +68,7 @@ func IsInGOPATH(thePath string) bool { thePath = filepath.ToSlash(thePath) } for _, gopath := range GetGOPATHs() { - if strings.Contains(thePath, gopath + "/src") { + if strings.Contains(thePath, gopath+"/src") { return true } } @@ -412,3 +413,22 @@ func SplitQuotedFields(in string) []string { return r } + +// GetFileModTime returns unix timestamp of `os.File.ModTime` for the given path. +func GetFileModTime(path string) int64 { + path = strings.Replace(path, "\\", "/", -1) + f, err := os.Open(path) + if err != nil { + beeLogger.Log.Errorf("Failed to open file on '%s': %s", path, err) + return time.Now().Unix() + } + defer f.Close() + + fi, err := f.Stat() + if err != nil { + beeLogger.Log.Errorf("Failed to get file stats: %s", err) + return time.Now().Unix() + } + + return fi.ModTime().Unix() +}