fix: 修改系统版本比较方法 (#4483)

This commit is contained in:
ssongliu 2024-04-12 11:04:06 +08:00 committed by GitHub
parent 96e48847d0
commit 222089d56a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View File

@ -43,7 +43,7 @@ func (u *UpgradeService) SearchUpgrade() (*dto.UpgradeInfo, error) {
global.LOG.Infof("load latest version failed, err: %v", err)
return nil, err
}
if !common.CompareVersion(string(latestVersion), currentVersion.Value) {
if !common.ComparePanelVersion(string(latestVersion), currentVersion.Value) {
return nil, err
}
upgrade.LatestVersion = latestVersion

View File

@ -45,6 +45,35 @@ func CompareVersion(version1, version2 string) bool {
return false
}
func ComparePanelVersion(version1, version2 string) bool {
if version1 == version2 {
return false
}
version1s := strings.Split(version1, ".")
version2s := strings.Split(version2, ".")
if len(version2s) > len(version1s) {
for i := 0; i < len(version2s)-len(version1s); i++ {
version1s = append(version1s, "0")
}
}
if len(version1s) > len(version2s) {
for i := 0; i < len(version1s)-len(version2s); i++ {
version2s = append(version2s, "0")
}
}
n := min(len(version1s), len(version2s))
for i := 0; i < n; i++ {
if version1s[i] == version2s[i] {
continue
} else {
return version1s[i] > version2s[i]
}
}
return true
}
func extractNumbers(version string) []string {
var numbers []string
start := -1