From 84fcd31704b15c42105b40c9e0a0db713f955032 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Fri, 17 Mar 2023 18:05:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/upgrade.go | 46 +++------------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/backend/app/service/upgrade.go b/backend/app/service/upgrade.go index 49ed4b9d6..4d9bec447 100644 --- a/backend/app/service/upgrade.go +++ b/backend/app/service/upgrade.go @@ -6,13 +6,13 @@ import ( "net/http" "os" "runtime" - "strconv" "strings" "time" "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/cmd" + "github.com/1Panel-dev/1Panel/backend/utils/common" "github.com/1Panel-dev/1Panel/backend/utils/files" ) @@ -43,8 +43,8 @@ func (u *UpgradeService) SearchUpgrade() (*dto.UpgradeInfo, error) { if err != nil { return nil, err } - isNew, err := compareVersion(currentVersion.Value, string(version)) - if !isNew || err != nil { + isNew := common.CompareVersion(string(version), currentVersion.Value) + if !isNew { return nil, err } @@ -176,43 +176,3 @@ func (u *UpgradeService) handleRollback(fileOp files.FileOp, originalDir string, } } - -func compareVersion(version, newVersion string) (bool, error) { - if version == newVersion { - return false, nil - } - if len(version) == 0 || len(newVersion) == 0 { - return false, fmt.Errorf("incorrect version or new version entered %v -- %v", version, newVersion) - } - versions := strings.Split(strings.ReplaceAll(version, "v", ""), ".") - if len(versions) != 3 { - return false, fmt.Errorf("incorrect version input %v", version) - } - newVersions := strings.Split(strings.ReplaceAll(newVersion, "v", ""), ".") - if len(newVersions) != 3 { - return false, fmt.Errorf("incorrect newVersions input %v", version) - } - version1, _ := strconv.Atoi(versions[0]) - newVersion1, _ := strconv.Atoi(newVersions[0]) - if newVersion1 > version1 { - return true, nil - } else if newVersion1 == version1 { - version2, _ := strconv.Atoi(versions[1]) - newVersion2, _ := strconv.Atoi(newVersions[1]) - if newVersion2 > version2 { - return true, nil - } else if newVersion2 == version2 { - version3, _ := strconv.Atoi(versions[2]) - newVersion3, _ := strconv.Atoi(newVersions[2]) - if newVersion3 > version3 { - return true, nil - } else { - return false, nil - } - } else { - return false, nil - } - } else { - return false, nil - } -}