From 952c480f4f4bedfaa8089ffb45311d63d0ab3fb4 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 6 Aug 2015 23:03:04 +0800 Subject: [PATCH] better version checker --- cmd/web.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/web.go b/cmd/web.go index 27e50cd2df..80b4feac14 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -17,6 +17,7 @@ import ( "github.com/Unknwon/macaron" "github.com/codegangsta/cli" + "github.com/go-xorm/xorm" "github.com/macaron-contrib/binding" "github.com/macaron-contrib/cache" "github.com/macaron-contrib/captcha" @@ -25,6 +26,7 @@ import ( "github.com/macaron-contrib/oauth2" "github.com/macaron-contrib/session" "github.com/macaron-contrib/toolbox" + "github.com/mcuadros/go-version" "gopkg.in/ini.v1" api "github.com/gogits/go-gogs-client" @@ -35,7 +37,6 @@ import ( "github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/bindata" - "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" @@ -79,6 +80,7 @@ func checkVersion() { // Check dependency version. checkers := []VerChecker{ + {"github.com/go-xorm/xorm", func() string { return xorm.Version }, "0.4.3.0806"}, {"github.com/Unknwon/macaron", macaron.Version, "0.5.4"}, {"github.com/macaron-contrib/binding", binding.Version, "0.1.0"}, {"github.com/macaron-contrib/cache", cache.Version, "0.0.7"}, @@ -88,9 +90,8 @@ func checkVersion() { {"gopkg.in/ini.v1", ini.Version, "1.3.4"}, } for _, c := range checkers { - ver := strings.Join(strings.Split(c.Version(), ".")[:3], ".") - if git.MustParseVersion(ver).LessThan(git.MustParseVersion(c.Expected)) { - log.Fatal(4, "Package '%s' version is too old(%s -> %s), did you forget to update?", c.ImportPath, ver, c.Expected) + if !version.Compare(c.Version(), c.Expected, ">=") { + log.Fatal(4, "Package '%s' version is too old(%s -> %s), did you forget to update?", c.ImportPath, c.Version(), c.Expected) } } }