lib/upgrade: 0.x to 1.0 is a minor upgrade

This removes the special handling of minor versions as major when the
actual major is zero, and adds the special case that upgrades from 0.x
to 1.x are considered minor. 0.x to 2.x or 1.x to 2.x etc are still
considered major.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4226
This commit is contained in:
Jakob Borg 2017-06-25 14:17:43 +00:00 committed by Audrius Butkevicius
parent 3641c97667
commit db1dc9985a
2 changed files with 23 additions and 13 deletions

View File

@ -104,20 +104,26 @@ func CompareVersions(a, b string) Relation {
for i := 0; i < minlen; i++ {
if arel[i] < brel[i] {
if i == 0 {
// major version difference
if arel[0] == 0 && brel[0] == 1 {
// special case, v0.x is equivalent in majorness to v1.x.
return Older
}
return MajorOlder
}
if i == 1 && arel[0] == 0 {
return MajorOlder
}
// minor or patch version difference
return Older
}
if arel[i] > brel[i] {
if i == 0 {
// major version difference
if arel[0] == 1 && brel[0] == 0 {
// special case, v0.x is equivalent in majorness to v1.x.
return Newer
}
return MajorNewer
}
if i == 1 && arel[0] == 0 {
return MajorNewer
}
// minor or patch version difference
return Newer
}
}

View File

@ -20,19 +20,21 @@ var versions = []struct {
{"0.1.2", "0.1.2", Equal},
{"0.1.3", "0.1.2", Newer},
{"0.1.1", "0.1.2", Older},
{"0.3.0", "0.1.2", MajorNewer},
{"0.0.9", "0.1.2", MajorOlder},
{"0.3.0", "0.1.2", Newer},
{"0.0.9", "0.1.2", Older},
{"1.3.0", "1.1.2", Newer},
{"1.0.9", "1.1.2", Older},
{"2.3.0", "1.1.2", MajorNewer},
{"1.0.9", "2.1.2", MajorOlder},
{"1.1.2", "0.1.2", MajorNewer},
{"0.1.2", "1.1.2", MajorOlder},
{"1.1.2", "0.1.2", Newer},
{"0.1.2", "1.1.2", Older},
{"2.1.2", "0.1.2", MajorNewer},
{"0.1.2", "2.1.2", MajorOlder},
{"0.1.10", "0.1.9", Newer},
{"0.10.0", "0.2.0", MajorNewer},
{"0.10.0", "0.2.0", Newer},
{"30.10.0", "4.9.0", MajorNewer},
{"0.9.0-beta7", "0.9.0-beta6", Newer},
{"0.9.0-beta7", "1.0.0-alpha", MajorOlder},
{"0.9.0-beta7", "1.0.0-alpha", Older},
{"1.0.0-alpha", "1.0.0-alpha.1", Older},
{"1.0.0-alpha.1", "1.0.0-alpha.beta", Older},
{"1.0.0-alpha.beta", "1.0.0-beta", Older},
@ -73,6 +75,8 @@ func TestSelectedRelease(t *testing.T) {
}{
// Within the same "major" (minor, in this case) select the newest
{"v0.12.24", false, []string{"v0.12.23", "v0.12.24", "v0.12.25", "v0.12.26"}, "v0.12.26"},
{"v0.12.24", false, []string{"v0.12.23", "v0.12.24", "v0.12.25", "v0.13.0"}, "v0.13.0"},
{"v0.12.24", false, []string{"v0.12.23", "v0.12.24", "v0.12.25", "v1.0.0"}, "v1.0.0"},
// Do no select beta versions when we are not allowed to
{"v0.12.24", false, []string{"v0.12.26", "v0.12.27-beta.42"}, "v0.12.26"},
{"v0.12.24-beta.0", false, []string{"v0.12.26", "v0.12.27-beta.42"}, "v0.12.26"},
@ -80,7 +84,7 @@ func TestSelectedRelease(t *testing.T) {
{"v0.12.24", true, []string{"v0.12.26", "v0.12.27-beta.42"}, "v0.12.27-beta.42"},
{"v0.12.24-beta.0", true, []string{"v0.12.26", "v0.12.27-beta.42"}, "v0.12.27-beta.42"},
// Select the best within the current major when there is a minor upgrade available
{"v0.12.24", false, []string{"v0.12.23", "v0.12.24", "v0.12.25", "v0.13.0"}, "v0.12.25"},
{"v0.12.24", false, []string{"v1.12.23", "v1.12.24", "v1.14.2", "v2.0.0"}, "v1.14.2"},
{"v1.12.24", false, []string{"v1.12.23", "v1.12.24", "v1.14.2", "v2.0.0"}, "v1.14.2"},
// Select the next major when we are at the best minor
{"v0.12.25", true, []string{"v0.12.23", "v0.12.24", "v0.12.25", "v0.13.0"}, "v0.13.0"},