mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Simplify logic for matching desired pkg arch with actual pkg arch
This commit is contained in:
parent
3babbcda94
commit
65289503d9
1 changed files with 25 additions and 23 deletions
|
@ -412,28 +412,6 @@ def latest_version(*names, **kwargs):
|
|||
if len(names) == 0:
|
||||
return ''
|
||||
|
||||
# Initialize the return dict with empty strings, and populate namearch_map.
|
||||
# namearch_map will provide a means of distinguishing between multiple
|
||||
# matches for the same package name, for example a target of 'glibc' on an
|
||||
# x86_64 arch would return both x86_64 and i686 versions.
|
||||
#
|
||||
# Note that the logic in the for loop below would place the osarch into the
|
||||
# map for noarch packages, but those cases are accounted for when iterating
|
||||
# through the 'yum list' results later on. If the match for that package is
|
||||
# a noarch, then the package is assumed to be noarch, and the namearch_map
|
||||
# is ignored.
|
||||
ret = {}
|
||||
namearch_map = {}
|
||||
for name in names:
|
||||
ret[name] = ''
|
||||
try:
|
||||
arch = name.rsplit('.', 1)[-1]
|
||||
if arch not in salt.utils.pkg.rpm.ARCHES:
|
||||
arch = __grains__['osarch']
|
||||
except ValueError:
|
||||
arch = __grains__['osarch']
|
||||
namearch_map[name] = arch
|
||||
|
||||
repo_arg = _get_repo_options(**kwargs)
|
||||
exclude_arg = _get_excludes_option(**kwargs)
|
||||
|
||||
|
@ -489,9 +467,33 @@ def latest_version(*names, **kwargs):
|
|||
# Package is not installed
|
||||
return True
|
||||
|
||||
ret = {}
|
||||
for name in names:
|
||||
# Derive desired pkg arch (for arch-specific packages) based on the
|
||||
# package name(s) passed to the function. On a 64-bit OS, "pkgame"
|
||||
# would be assumed to match the osarch, while "pkgname.i686" would
|
||||
# have an arch of "i686". This desired arch is then compared against
|
||||
# the updates derived from _yum_pkginfo() above, so that we can
|
||||
# distinguish an update for a 32-bit version of a package from its
|
||||
# 64-bit counterpart.
|
||||
try:
|
||||
arch = name.rsplit('.', 1)[-1]
|
||||
if arch not in salt.utils.pkg.rpm.ARCHES:
|
||||
arch = __grains__['osarch']
|
||||
except ValueError:
|
||||
arch = __grains__['osarch']
|
||||
|
||||
# This loop will iterate over the updates derived by _yum_pkginfo()
|
||||
# above, which have been sorted descendingly by version number,
|
||||
# ensuring that the latest available version for the named package is
|
||||
# examined first. The call to _check_cur() will ensure that a package
|
||||
# seen by yum as "available" will only be detected as an upgrade if it
|
||||
# has a version higher than all currently-installed versions of the
|
||||
# package.
|
||||
for pkg in (x for x in updates if x.name == name):
|
||||
if pkg.arch == 'noarch' or pkg.arch == namearch_map[name] \
|
||||
# This if/or statement makes sure that we account for noarch
|
||||
# packages as well as arch-specific packages.
|
||||
if pkg.arch == 'noarch' or pkg.arch == arch \
|
||||
or salt.utils.pkg.rpm.check_32(pkg.arch):
|
||||
if _check_cur(pkg):
|
||||
ret[name] = pkg.version
|
||||
|
|
Loading…
Add table
Reference in a new issue