fixes saltstack/salt#66260 aptpkg.remove unable to locate package for non-existent package

This commit is contained in:
nicholasmhughes 2024-03-22 20:56:16 -04:00 committed by Pedro Algarvio
parent 35bc5fc46b
commit 4a6fac0934
3 changed files with 17 additions and 2 deletions

1
changelog/66260.fixed.md Normal file
View file

@ -0,0 +1 @@
Fixed `aptpkg.remove` "unable to locate package" error for non-existent package

View file

@ -1067,9 +1067,17 @@ def _uninstall(action="remove", name=None, pkgs=None, **kwargs):
old = list_pkgs()
old_removed = list_pkgs(removed=True)
targets = salt.utils.pkg.match_wildcard(old, pkg_params)
targets = [
_pkg for _pkg in salt.utils.pkg.match_wildcard(old, pkg_params) if _pkg in old
]
if action == "purge":
targets.update(salt.utils.pkg.match_wildcard(old_removed, pkg_params))
targets.extend(
[
_pkg
for _pkg in salt.utils.pkg.match_wildcard(old_removed, pkg_params)
if _pkg in old_removed
]
)
if not targets:
return {}
cmd = ["apt-get", "-q", "-y", action]

View file

@ -398,3 +398,9 @@ def test_aptpkg_remove_wildcard():
assert ret["nginx-light"]["old"]
assert not ret["nginx-doc"]["new"]
assert ret["nginx-doc"]["old"]
@pytest.mark.skip_if_not_root
def test_aptpkg_remove_unknown_package():
ret = aptpkg.remove(name="thispackageistotallynotthere")
assert not ret