mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #25369 from alprs/fix-apt_version_cmp
Fix aptpkg.version_cmp
This commit is contained in:
commit
c9fe10e7aa
1 changed files with 13 additions and 1 deletions
|
@ -1127,7 +1127,19 @@ def version_cmp(pkg1, pkg2):
|
|||
# and also do not rely on shell.
|
||||
if HAS_APTPKG:
|
||||
try:
|
||||
return apt_pkg.version_compare(pkg1, pkg2)
|
||||
# the apt_pkg module needs to be manually initialized
|
||||
apt_pkg.init_system()
|
||||
|
||||
# if there is a difference in versions, apt_pkg.version_compare will
|
||||
# return an int representing the difference in minor versions, or
|
||||
# 1/-1 if the difference is smaller than minor versions. normalize
|
||||
# to -1, 0 or 1.
|
||||
ret = apt_pkg.version_compare(pkg1, pkg2)
|
||||
if ret > 0:
|
||||
return 1
|
||||
if ret < 0:
|
||||
return -1
|
||||
return 0
|
||||
except (TypeError, ValueError):
|
||||
# try to use shell version in case of errors via
|
||||
# the python binding
|
||||
|
|
Loading…
Add table
Reference in a new issue