fix(deb): avoid python-apt for installed package checks
Metadata
Current evaluation
No evaluation has been recorded for this issue yet.
Issue body
Fixes #976
## Background
On Ubuntu Plucky, `/etc/apt/sources.list` may be absent because the system uses deb822-based configuration exclusively.
When `python-apt` initializes its cache (`apt.cache.Cache(rootdir="/")`), it attempts to ensure certain files exist, including `/etc/apt/sources.list`.
If the file is missing, it attempts to create it. When running as an unprivileged user (e.g. during integration tests), this results in:
PermissionError: [Errno 13] Permission denied: '//etc/apt/sources.list'
This failure happens in the installed-package check path, before any actual installation occurs.
## What this change does
For the host `install_packages()` path only:
- Replace the use of `python-apt` for:
- checking whether packages are already installed
- constructing the returned `package=version` list
- Use `dpkg-query` instead for installed-state detection.
Actual installation still uses:
apt-get install ...
Stage package handling and other apt-cache–based functionality remain unchanged.
## Rationale
For determining whether a package is installed, `dpkg-query` is:
- sufficient
- does not require root
- independent of apt source configuration
- unaffected by deb822 migration
Using `python-apt` for this specific optimization is unnecessary and causes failures on systems without `/etc/apt/sources.list`.
## Trade-offs
- `dpkg-query` does not resolve virtual packages in the same way as `python-apt`.
- However:
- `apt-get install` still performs dependency and virtual package resolution.
- The returned `package=version` list is already documented as “best effort”.
- Typical build-packages (cmake, gcc, pkg-config, etc.) are concrete packages.
## Scope
This change only affects the installed-check optimization and version reporting for host installs.
All apt-cache usage for stage packages remains intact.
Evaluation history
No evaluation history available.