Don't consider packages missing from the cache an error on remove

Fixes #2017.
This commit is contained in:
Daniel Hokka Zakrisson 2013-02-19 23:18:17 +01:00
parent d2bf205a5d
commit 3f2fd22ed4

View file

@ -100,11 +100,14 @@ def package_split(pkgspec):
else: else:
return parts[0], None return parts[0], None
def package_status(m, pkgname, version, cache): def package_status(m, pkgname, version, cache, state):
try: try:
pkg = cache[pkgname] pkg = cache[pkgname]
except KeyError: except KeyError:
m.fail_json(msg="No package matching '%s' is available" % pkgname) if state == 'install':
m.fail_json(msg="No package matching '%s' is available" % pkgname)
else:
return False, False
if version: if version:
try : try :
return pkg.is_installed and pkg.installed.version == version, False return pkg.is_installed and pkg.installed.version == version, False
@ -122,7 +125,7 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None, install_reco
packages = "" packages = ""
for package in pkgspec: for package in pkgspec:
name, version = package_split(package) name, version = package_split(package)
installed, upgradable = package_status(m, name, version, cache) installed, upgradable = package_status(m, name, version, cache, state='install')
if not installed or (upgrade and upgradable): if not installed or (upgrade and upgradable):
packages += "'%s' " % package packages += "'%s' " % package
@ -150,14 +153,16 @@ def remove(m, pkgspec, cache, purge=False):
packages = "" packages = ""
for package in pkgspec: for package in pkgspec:
name, version = package_split(package) name, version = package_split(package)
installed, upgradable = package_status(m, name, version, cache) installed, upgradable = package_status(m, name, version, cache, state='remove')
if installed: if installed:
packages += "'%s' " % package packages += "'%s' " % package
if len(packages) == 0: if len(packages) == 0:
m.exit_json(changed=False) m.exit_json(changed=False)
else: else:
purge = '--purge' if purge else '' purge = ''
if purge:
purge = '--purge'
cmd = "%s -q -y %s remove %s" % (APT, purge,packages) cmd = "%s -q -y %s remove %s" % (APT, purge,packages)
rc, out, err = m.run_command(cmd) rc, out, err = m.run_command(cmd)
if rc: if rc: