Skip to content

Commit

Permalink
Don't consider packages missing from the cache an error on remove
Browse files Browse the repository at this point in the history
  • Loading branch information
dhozac committed Feb 19, 2013
1 parent d2bf205 commit 3f2fd22
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions library/apt
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ def package_split(pkgspec):
else:
return parts[0], None

def package_status(m, pkgname, version, cache):
def package_status(m, pkgname, version, cache, state):
try:
pkg = cache[pkgname]
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:
try :
return pkg.is_installed and pkg.installed.version == version, False
Expand All @@ -122,7 +125,7 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None, install_reco
packages = ""
for package in pkgspec:
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):
packages += "'%s' " % package

Expand Down Expand Up @@ -150,14 +153,16 @@ def remove(m, pkgspec, cache, purge=False):
packages = ""
for package in pkgspec:
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:
packages += "'%s' " % package

if len(packages) == 0:
m.exit_json(changed=False)
else:
purge = '--purge' if purge else ''
purge = ''
if purge:
purge = '--purge'
cmd = "%s -q -y %s remove %s" % (APT, purge,packages)
rc, out, err = m.run_command(cmd)
if rc:
Expand Down

0 comments on commit 3f2fd22

Please sign in to comment.