Skip to content

Commit c8973de

Browse files
committed
fix(self-update): use CompareVersions to prevent downgrading to older releases
1 parent 56e0fe1 commit c8973de

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

cmd/43.self-update.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/snowdreamtech/unirtm/internal/cli/output"
2020
"github.com/snowdreamtech/unirtm/internal/pkg/env"
2121
pkgHttp "github.com/snowdreamtech/unirtm/internal/pkg/http"
22+
"github.com/snowdreamtech/unirtm/internal/pkg/version"
2223
"github.com/spf13/cobra"
2324
)
2425

@@ -299,11 +300,14 @@ func runSelfUpdate(cmd *cobra.Command, args []string) error {
299300
} else {
300301
spinner.Success(fmt.Sprintf("Found release: %s", releaseInfo.TagName))
301302

302-
// Version comparison with normalized tags (strip leading 'v')
303-
if target == "latest" && normalizeVersion(current) == normalizeVersion(releaseInfo.TagName) {
304-
output.Infof("You are already using the latest version (%s).", current)
305-
if !selfUpdateYes {
306-
return nil
303+
// Version comparison: avoid downgrading if the current version is newer or equal
304+
if target == "latest" {
305+
cmp := version.CompareVersions(current, releaseInfo.TagName)
306+
if cmp >= 0 {
307+
output.Infof("You are already using the latest version (%s).", current)
308+
if !selfUpdateYes {
309+
return nil
310+
}
307311
}
308312
}
309313

0 commit comments

Comments
 (0)