Skip to content

Commit

Permalink
distrodef: fix incorrect detection of centos-10 vs 10.0
Browse files Browse the repository at this point in the history
This commit fixes the issue that when the `os-release` has an
`ID=10.0` in it, a distrodef file ending with `-10` will not
be identified as the closest match because the code is using
a "strictly bigger" relation to sort versions but for semver
`10.0` and `10` are just identical so we need ">=" instead
of ">" (see the actual diff).

We saw this issue with the `rhel-10.0` beta that has a
`VERSION_ID=10.0` field and a `rhel-10.yaml` distro-def. Here the
code was skipping over rhel-10.yaml and felt back to rhel-9 when
it really should have used `rhel-10.yaml`.

Thanks to Achilleas for tracking this down.
  • Loading branch information
mvo5 committed Feb 7, 2025
1 parent 4f86598 commit 2fbc83c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bib/internal/distrodef/distrodef.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func findDistroDef(defDirs []string, distro, wantedVerStr string) (string, error
if err != nil {
return "", fmt.Errorf("cannot parse distro version from %q: %w", m, err)
}
if wantedVer.Compare(haveVer) > 0 && haveVer.Compare(bestFuzzyVer) > 0 {
if wantedVer.Compare(haveVer) >= 0 && haveVer.Compare(bestFuzzyVer) > 0 {
bestFuzzyVer = haveVer
bestFuzzyMatch = m
}
Expand Down
10 changes: 10 additions & 0 deletions bib/internal/distrodef/distrodef_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ func TestFindDistroDefMultiFuzzyMinorReleases(t *testing.T) {
assert.True(t, strings.HasSuffix(def, "b/b/centos-9.10.yaml"), def)
}

func TestFindDistroDefMultiFuzzyMinorReleasesIsZero(t *testing.T) {
defDirs := makeFakeDistrodefRoot(t, []string{
"a/centos-9.yaml",
"a/centos-10.yaml",
})
def, err := findDistroDef(defDirs, "centos", "10.0")
assert.NoError(t, err)
assert.True(t, strings.HasSuffix(def, "a/centos-10.yaml"), def)
}

func TestFindDistroDefMultiFuzzyError(t *testing.T) {
defDirs := makeFakeDistrodefRoot(t, []string{
"a/fedora-40.yaml",
Expand Down

0 comments on commit 2fbc83c

Please sign in to comment.