From 4dde2c59fff5b60c5f40b0e4805b7b9d51b01a2f Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 30 Jun 2014 15:57:36 +0800 Subject: [PATCH] fix the parser.go lastupdate --- parser.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/parser.go b/parser.go index 7e8f2046..f8818295 100644 --- a/parser.go +++ b/parser.go @@ -165,12 +165,12 @@ func compareFile(pkgRealpath string) bool { return true } json.Unmarshal(content, &pkgLastupdate) - ft, err := os.Lstat(pkgRealpath) + lastupdate, err := getpathTime(pkgRealpath) if err != nil { return true } if v, ok := pkgLastupdate[pkgRealpath]; ok { - if ft.ModTime().UnixNano() <= v { + if lastupdate <= v { return false } } @@ -179,14 +179,27 @@ func compareFile(pkgRealpath string) bool { } func savetoFile(pkgRealpath string) { - ft, err := os.Lstat(pkgRealpath) + lastupdate, err := getpathTime(pkgRealpath) if err != nil { return } - pkgLastupdate[pkgRealpath] = ft.ModTime().UnixNano() + pkgLastupdate[pkgRealpath] = lastupdate d, err := json.Marshal(pkgLastupdate) if err != nil { return } ioutil.WriteFile(path.Join(AppPath, lastupdateFilename), d, os.ModePerm) } + +func getpathTime(pkgRealpath string) (lastupdate int64, err error) { + fl, err := ioutil.ReadDir(pkgRealpath) + if err != nil { + return lastupdate, err + } + for _, f := range fl { + if lastupdate < f.ModTime().UnixNano() { + lastupdate = f.ModTime().UnixNano() + } + } + return lastupdate, nil +}