From 0c6cd61c762671718a983024bf75be73ae8b736b Mon Sep 17 00:00:00 2001 From: Linus Yang Date: Sat, 3 Nov 2018 10:37:46 +0800 Subject: [PATCH] Improve version comparison of miuimon.go --- .gitignore | 1 + tools/miuimon/Makefile | 8 ++++++++ tools/{miuimon.go => miuimon/main.go} | 5 +++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tools/miuimon/Makefile rename tools/{miuimon.go => miuimon/main.go} (97%) diff --git a/.gitignore b/.gitignore index 1ec24f6..8641484 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ *.aria2 /tools/win32/ compare/ +/tools/miuimon/miuimon diff --git a/tools/miuimon/Makefile b/tools/miuimon/Makefile new file mode 100644 index 0000000..67685e0 --- /dev/null +++ b/tools/miuimon/Makefile @@ -0,0 +1,8 @@ +miuimon: main.go + go get -d -v ./... + go build -o $@ -v -ldflags "-s -w" main.go + +clean: + rm -f miuimon + +.PHONY: clean \ No newline at end of file diff --git a/tools/miuimon.go b/tools/miuimon/main.go similarity index 97% rename from tools/miuimon.go rename to tools/miuimon/main.go index 42399a5..5fb7577 100644 --- a/tools/miuimon.go +++ b/tools/miuimon/main.go @@ -16,6 +16,7 @@ import ( "time" "github.com/google/go-github/github" + gover "github.com/mcuadros/go-version" "github.com/mmcdole/gofeed" "github.com/yhat/scrape" "golang.org/x/net/html" @@ -182,14 +183,14 @@ func getNewDeploy(currentVer, currentDeploy string, version = currentVer deploy = []byte(currentDeploy) err = nil - if miuiVer > currentVer || force { + if gover.Compare(miuiVer, currentVer, ">") || force { version = miuiVer euVer, euUrl = getEu(miuiVer) if euVer == miuiVer || force { deploy = newDeployFile(miuiVer, miuiUrl, euUrl, currentDeploy) } } - if miuiVer <= currentVer { + if gover.Compare(miuiVer, currentVer, "<=") { err = errors.New(fmt.Sprintf("MIUI China (current: %s)", miuiVer)) } else if euVer != miuiVer { err = errors.New(fmt.Sprintf("xiaomi.eu (current: %s)", euVer))