fix: correct platform format in version detection
Created version package for semantic version comparison. Fixed GetLatestVersionByTypeAndArch to use combined platform format. Replaced inline version comparison with reusable version.Compare().
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/Fimeg/RedFlag/aggregator-server/internal/database/queries"
|
||||
"github.com/Fimeg/RedFlag/aggregator-server/internal/models"
|
||||
"github.com/Fimeg/RedFlag/aggregator-server/internal/services"
|
||||
"github.com/Fimeg/RedFlag/aggregator-server/internal/version"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -578,8 +579,10 @@ func (h *AgentUpdateHandler) CheckForUpdateAvailable(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if this is actually newer than current version
|
||||
hasUpdate := isVersionUpgrade(latestVersion, agent.CurrentVersion)
|
||||
// Check if this is actually newer than current version using version package
|
||||
currentVer := version.Version(agent.CurrentVersion)
|
||||
latestVer := version.Version(latestVersion)
|
||||
hasUpdate := currentVer.IsUpgrade(latestVer)
|
||||
|
||||
log.Printf("[DEBUG] Version comparison - latest: %s, current: %s, hasUpdate: %v for platform: %s/%s", latestVersion, agent.CurrentVersion, hasUpdate, osType, osArch)
|
||||
|
||||
@@ -589,11 +592,12 @@ func (h *AgentUpdateHandler) CheckForUpdateAvailable(c *gin.Context) {
|
||||
log.Printf("[DEBUG] Detected sub-version upgrade: %s -> %s", agent.CurrentVersion, latestVersion)
|
||||
}
|
||||
|
||||
platform := version.Platform(osType + "-" + osArch)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"hasUpdate": hasUpdate,
|
||||
"currentVersion": agent.CurrentVersion,
|
||||
"latestVersion": latestVersion,
|
||||
"platform": osType + "-" + osArch,
|
||||
"platform": platform.String(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -641,40 +645,4 @@ func (h *AgentUpdateHandler) GetUpdateStatus(c *gin.Context) {
|
||||
"progress": progress,
|
||||
"error": errorMsg,
|
||||
})
|
||||
}
|
||||
|
||||
// isVersionUpgrade returns true if new version is greater than current version
|
||||
func isVersionUpgrade(newVersion string, currentVersion string) bool {
|
||||
// Parse semantic versions
|
||||
newParts := strings.Split(newVersion, ".")
|
||||
curParts := strings.Split(currentVersion, ".")
|
||||
|
||||
// Pad arrays to 3 parts
|
||||
for len(newParts) < 3 {
|
||||
newParts = append(newParts, "0")
|
||||
}
|
||||
for len(curParts) < 3 {
|
||||
curParts = append(curParts, "0")
|
||||
}
|
||||
|
||||
// Convert to integers for comparison
|
||||
newMajor, _ := strconv.Atoi(newParts[0])
|
||||
newMinor, _ := strconv.Atoi(newParts[1])
|
||||
newPatch, _ := strconv.Atoi(newParts[2])
|
||||
|
||||
curMajor, _ := strconv.Atoi(curParts[0])
|
||||
curMinor, _ := strconv.Atoi(curParts[1])
|
||||
curPatch, _ := strconv.Atoi(curParts[2])
|
||||
|
||||
// Check if new > current (not equal, not less)
|
||||
if newMajor > curMajor {
|
||||
return true
|
||||
}
|
||||
if newMajor == curMajor && newMinor > curMinor {
|
||||
return true
|
||||
}
|
||||
if newMajor == curMajor && newMinor == curMinor && newPatch > curPatch {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user