Commit d4ed146c authored by szh's avatar szh

添加版本号比较

parent 3a4e593a
......@@ -16,6 +16,7 @@ const (
MV_ERROR = 5009
TRY_LATER = 5010
DF_ERROR = 5011
VERSION_UPDATE_ERROR = 5012
ERROR_EXIST_TAG = 10001
ERROR_EXIST_TAG_FAIL = 10002
ERROR_NOT_EXIST_TAG = 10003
......
......@@ -11,6 +11,7 @@ var MsgFlags = map[int]string{
MV_ERROR: "移动文件出错",
TRY_LATER: "其他任务进行中,稍后再试",
DF_ERROR: "df命令执行异常",
VERSION_UPDATE_ERROR: "版本更新异常,请检查当前版本和更新版本",
ERROR_EXIST_TAG: "已存在该标签名称",
ERROR_EXIST_TAG_FAIL: "获取已存在标签失败",
ERROR_NOT_EXIST_TAG: "该标签不存在",
......
......@@ -54,6 +54,7 @@ func GetExternal() (string,error) {
return string(content),nil
}
//两个以上空格替换成一个空格
func DeleteExtraSpace(s string) string {
//删除字符串中的多余空格,有多个空格时,仅保留一个空格
s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
......@@ -68,3 +69,33 @@ func DeleteExtraSpace(s string) string {
}
return string(s2)
}
//字符串版本号比较
func VersionCompare(version string) string {
// ISO/IEC 14651:2011
const maxByte = 1<<8 - 1
vo := make([]byte, 0, len(version)+8)
j := -1
for i := 0; i < len(version); i++ {
b := version[i]
if '0' > b || b > '9' {
vo = append(vo, b)
j = -1
continue
}
if j == -1 {
vo = append(vo, 0x00)
j = len(vo) - 1
}
if vo[j] == 1 && vo[j+1] == '0' {
vo[j+1] = b
continue
}
if vo[j]+1 > maxByte {
panic("VersionCompare: invalid version")
}
vo = append(vo, b)
vo[j]++
}
return string(vo)
}
......@@ -68,6 +68,13 @@ func UpdatePai(c *gin.Context) {
app.DPercent.Flag = false
return
}
version := util.VersionCompare(app.GetVersion())
updateversion := util.VersionCompare(req.Version)
if updateversion <= version {
appG.Response(http.StatusOK, e.VERSION_UPDATE_ERROR, nil)
app.DPercent.Flag = false
return
}
name := setting.Chain33Pai.Name+"_"+req.Version+".tar.gz"
url := setting.Chain33Pai.DownloadUrl+ name
//oss下载更新包
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment