[fix] issue #30638 - onlyupgrade handling (#31577)

Fixes #30638
pull/38586/head
ppanczyk 7 years ago committed by ansibot
parent 44fc3459cf
commit 7850dfa9d9

@ -350,20 +350,21 @@ def package_status(m, pkgname, version, cache, state):
if provided_packages: if provided_packages:
is_installed = False is_installed = False
upgradable = False upgradable = False
version_ok = False
# when virtual package providing only one package, look up status of target package # when virtual package providing only one package, look up status of target package
if cache.is_virtual_package(pkgname) and len(provided_packages) == 1: if cache.is_virtual_package(pkgname) and len(provided_packages) == 1:
package = provided_packages[0] package = provided_packages[0]
installed, upgradable, has_files = package_status(m, package.name, version, cache, state='install') installed, version_ok, upgradable, has_files = package_status(m, package.name, version, cache, state='install')
if installed: if installed:
is_installed = True is_installed = True
return is_installed, upgradable, False return is_installed, version_ok, upgradable, False
m.fail_json(msg="No package matching '%s' is available" % pkgname) m.fail_json(msg="No package matching '%s' is available" % pkgname)
except AttributeError: except AttributeError:
# python-apt version too old to detect virtual packages # python-apt version too old to detect virtual packages
# mark as upgradable and let apt-get install deal with it # mark as upgradable and let apt-get install deal with it
return False, True, False return False, False, True, False
else: else:
return False, False, False return False, False, False, False
try: try:
has_files = len(pkg.installed_files) > 0 has_files = len(pkg.installed_files) > 0
except UnicodeDecodeError: except UnicodeDecodeError:
@ -381,6 +382,7 @@ def package_status(m, pkgname, version, cache, state):
# assume older version of python-apt is installed # assume older version of python-apt is installed
package_is_installed = pkg.isInstalled package_is_installed = pkg.isInstalled
version_is_installed = package_is_installed
if version: if version:
versions = package_versions(pkgname, pkg, cache._cache) versions = package_versions(pkgname, pkg, cache._cache)
avail_upgrades = fnmatch.filter(versions, version) avail_upgrades = fnmatch.filter(versions, version)
@ -391,8 +393,8 @@ def package_status(m, pkgname, version, cache, state):
except AttributeError: except AttributeError:
installed_version = pkg.installedVersion installed_version = pkg.installedVersion
# Only claim the package is installed if the version is matched as well # check if the version is matched as well
package_is_installed = fnmatch.fnmatch(installed_version, version) version_is_installed = fnmatch.fnmatch(installed_version, version)
# Only claim the package is upgradable if a candidate matches the version # Only claim the package is upgradable if a candidate matches the version
package_is_upgradable = False package_is_upgradable = False
@ -409,7 +411,7 @@ def package_status(m, pkgname, version, cache, state):
# assume older version of python-apt is installed # assume older version of python-apt is installed
package_is_upgradable = pkg.isUpgradable package_is_upgradable = pkg.isUpgradable
return package_is_installed, package_is_upgradable, has_files return package_is_installed, version_is_installed, package_is_upgradable, has_files
def expand_dpkg_options(dpkg_options_compressed): def expand_dpkg_options(dpkg_options_compressed):
@ -519,10 +521,10 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None,
name, version = package_split(package) name, version = package_split(package)
package_names.append(name) package_names.append(name)
installed, upgradable, has_files = package_status(m, name, version, cache, state='install') installed, installed_version, upgradable, has_files = package_status(m, name, version, cache, state='install')
if (not installed and not only_upgrade) or (upgrade and upgradable): if (not installed and not only_upgrade) or (installed and not installed_version) or (upgrade and upgradable):
pkg_list.append("'%s'" % package) pkg_list.append("'%s'" % package)
if installed and upgradable and version: if installed_version and upgradable and version:
# This happens when the package is installed, a newer version is # This happens when the package is installed, a newer version is
# available, and the version is a wildcard that matches both # available, and the version is a wildcard that matches both
# #
@ -684,8 +686,8 @@ def remove(m, pkgspec, cache, purge=False, force=False,
pkgspec = expand_pkgspec_from_fnmatches(m, pkgspec, cache) pkgspec = expand_pkgspec_from_fnmatches(m, pkgspec, cache)
for package in pkgspec: for package in pkgspec:
name, version = package_split(package) name, version = package_split(package)
installed, upgradable, has_files = package_status(m, name, version, cache, state='remove') installed, installed_version, upgradable, has_files = package_status(m, name, version, cache, state='remove')
if installed or (has_files and purge): if installed_version or (has_files and purge):
pkg_list.append("'%s'" % package) pkg_list.append("'%s'" % package)
packages = ' '.join(pkg_list) packages = ' '.join(pkg_list)

Loading…
Cancel
Save