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

Move getFileModTime() to utils package

This commit is contained in:
Faissal Elamraoui 2017-04-02 23:36:17 +02:00
parent 5600cb1c36
commit f80384a9f5
2 changed files with 22 additions and 21 deletions

View File

@ -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()

View File

@ -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()
}