lib/upgrade: Always return latest version, even if older than current (fixes #4654)

The only special check remaining is the one to prefer a minor upgrade
over a major one.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4672
This commit is contained in:
Jakob Borg 2018-01-15 12:13:25 +00:00 committed by Audrius Butkevicius
parent bd63fd73b1
commit fcc6a677a5
1 changed files with 3 additions and 12 deletions

View File

@ -134,34 +134,25 @@ func SelectLatestRelease(rels []Release, current string, upgradeToPreReleases bo
var selected Release
for _, rel := range rels {
switch CompareVersions(rel.Tag, current) {
case Older, MajorOlder:
// This is older than what we're already running
continue
case MajorNewer:
if CompareVersions(rel.Tag, current) == MajorNewer {
// We've found a new major version. That's fine, but if we've
// already found a minor upgrade that is acceptable we should go
// with that one first and then revisit in the future.
if selected.Tag != "" && CompareVersions(selected.Tag, current) == Newer {
return selected, nil
}
// else it may be viable, do the needful below
default:
// New minor release, do the usual processing
}
if rel.Prerelease && !upgradeToPreReleases {
l.Debugln("skipping pre-release", rel.Tag)
continue
}
for _, asset := range rel.Assets {
assetName := path.Base(asset.Name)
// Check for the architecture
expectedRelease := releaseName(rel.Tag)
l.Debugf("expected release asset %q", expectedRelease)
l.Debugln("considering release", assetName)
if strings.HasPrefix(assetName, expectedRelease) {
l.Debugln("selected", rel.Tag)
selected = rel
}
}