package: Uninstall packages even if they are not in apt cache

Tests:

- Install matrix-synapse app by adding 'unstable' in apt sources.list. Then
remove 'unstable' from apt sources.list. Then matrix-synapse package will no
longer be found in the apt's cache.

- Try to uninstall the package. Without patch, the process errors out. With
patch, uninstall completes successfully.

- While matrix-synapse app is installed and apt cache does not contain
matrix-synapse package, install and uninstall bepasty app. Without patch,
uninstall fails. With patch, uninstall succeeds.

- Install and uninstall minetest app. 3d armor mod package is successfully
installed.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
Sunil Mohan Adapa 2025-08-06 11:16:15 -07:00 committed by Joseph Nuthalapati
parent 3f19c91007
commit e26a4b71eb
No known key found for this signature in database
GPG Key ID: 5398F00A2FA43C35

View File

@ -194,8 +194,11 @@ class Packages(app_module.FollowerComponent):
# Ensure package list is update-to-date before looking at dependencies.
refresh_package_lists()
# List of packages to purge from the system
packages = self.get_actual_packages()
# List of packages to purge from the system. Be resilient to a package
# not being found in apt's cache by not using get_actual_packages(). If
# a package expression is listed as (package1 | package2) then try to
# remove both packages.
packages = self.possible_packages
logger.info('App\'s list of packages to remove: %s', packages)
packages = self._filter_packages_to_keep(packages)
@ -304,7 +307,7 @@ class Packages(app_module.FollowerComponent):
# Remove packages used by other installed apps
for component in app.get_components_of_type(Packages):
keep_packages |= set(component.get_actual_packages())
keep_packages |= set(component.possible_packages)
# Get list of all the dependencies of packages to keep.
keep_packages_with_deps: set[str] = set()