mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix rpm_lowpkg version comparison logic when using rpm-vercmp
This commit is contained in:
parent
cb38c39fdb
commit
ffa03e3847
3 changed files with 18 additions and 9 deletions
1
changelog/63317.fixed.md
Normal file
1
changelog/63317.fixed.md
Normal file
|
@ -0,0 +1 @@
|
|||
Fix rpm_lowpkg version comparison logic when using rpm-vercmp and only one version has a release number.
|
|
@ -740,7 +740,19 @@ def version_cmp(ver1, ver2, ignore_epoch=False):
|
|||
except AttributeError:
|
||||
log.debug("rpmUtils.miscutils.compareEVR is not available")
|
||||
|
||||
# If one EVR is missing a release but not the other and they
|
||||
# otherwise would be equal, ignore the release. This can happen if
|
||||
# e.g. you are checking if a package version 3.2 is satisfied by
|
||||
# 3.2-1.
|
||||
(ver1_e, ver1_v, ver1_r) = salt.utils.pkg.rpm.version_to_evr(ver1)
|
||||
(ver2_e, ver2_v, ver2_r) = salt.utils.pkg.rpm.version_to_evr(ver2)
|
||||
|
||||
if not ver1_r or not ver2_r:
|
||||
ver1_r = ver2_r = ""
|
||||
|
||||
if cmp_func is None:
|
||||
ver1 = f"{ver1_e}:{ver1_v}-{ver1_r}"
|
||||
ver2 = f"{ver2_e}:{ver2_v}-{ver2_r}"
|
||||
if salt.utils.path.which("rpmdev-vercmp"):
|
||||
log.warning(
|
||||
"Installing the rpmdevtools package may surface dev tools in"
|
||||
|
@ -790,16 +802,10 @@ def version_cmp(ver1, ver2, ignore_epoch=False):
|
|||
" comparisons"
|
||||
)
|
||||
else:
|
||||
# If one EVR is missing a release but not the other and they
|
||||
# otherwise would be equal, ignore the release. This can happen if
|
||||
# e.g. you are checking if a package version 3.2 is satisfied by
|
||||
# 3.2-1.
|
||||
(ver1_e, ver1_v, ver1_r) = salt.utils.pkg.rpm.version_to_evr(ver1)
|
||||
(ver2_e, ver2_v, ver2_r) = salt.utils.pkg.rpm.version_to_evr(ver2)
|
||||
if not ver1_r or not ver2_r:
|
||||
ver1_r = ver2_r = ""
|
||||
|
||||
if HAS_PY_RPM:
|
||||
ver1 = f"{ver1_v}-{ver1_r}"
|
||||
ver2 = f"{ver2_v}-{ver2_r}"
|
||||
|
||||
# handle epoch version comparison first
|
||||
# rpm_vercmp.vercmp does not handle epoch version comparison
|
||||
ret = salt.utils.versions.version_cmp(ver1_e, ver2_e)
|
||||
|
|
|
@ -281,6 +281,8 @@ def test_version_cmp_rpm_all_libraries(rpm_lib):
|
|||
assert 0 == rpm.version_cmp("3:2.9.1-6.el7.4", "3:2.9.1-6.el7.4")
|
||||
assert -1 == rpm.version_cmp("3:2.9.1-6.el7.4", "3:2.9.1-7.el7.4")
|
||||
assert 1 == rpm.version_cmp("3:2.9.1-8.el7.4", "3:2.9.1-7.el7.4")
|
||||
assert 0 == rpm.version_cmp("3.23-6.el9", "3.23")
|
||||
assert 0 == rpm.version_cmp("3.23", "3.23-6.el9")
|
||||
|
||||
|
||||
def test_version_cmp_rpm():
|
||||
|
|
Loading…
Add table
Reference in a new issue