chroot: apk: use apk.static in all cases (MR 2463)

In 0b4fb9119f (chroot: always run apk static v2 (MR 2423)) we adjusted
install_run_apk() to run apk static on the host and pass in the local
binary repo with "--repository". This function can call apk in two ways,
either with the progress bar handling or without, the second case was
never updated and still ran apk inside the chroot incorrectly and with
an incorrect --repository flag.

Let's finish the job by refactoring helpers/apk.py to support all our
usecases and pointing everything to it, removing the last few situations
where we call "pmb.chroot.root(["apk", ...]).

The apk_with_progress() function is replaced by a generic "run()"
function which takes a boolean to indicate if we should render apk
progress.

Additionally, a new cache_clean() function is added so that "pmbootstrap
zap --pkgs-online-mismatch" can FINALLY be refactored to not rely on a
chroot existing. This requires some hacks but nothing serious, see the
comments in the function for details.

The chroot.init() code is now simplified since handling the --root,
--arch, --cache-dir, and --repository flags is now all done by
apk._prepare_cmd() as and when appropriate.

Lastly, this fixes a (previously unnoticed) bug where apk.static was
actually using /var/cache/apk on your host machine for its cache... This
is definitely not good behaviour....

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-10-27 20:56:54 +01:00
parent 12846f3b8e
commit 42158637a7
No known key found for this signature in database
GPG key ID: 0583312B195F64B6
7 changed files with 154 additions and 59 deletions

View file

@ -16,6 +16,7 @@ from pmb.core.arch import Arch
from pmb.core.pkgrepo import pkgrepo_names
from pmb.helpers import logging
from pathlib import Path
from typing import Literal
import pmb.config.pmaports
from pmb.meta import Cache
@ -54,11 +55,14 @@ def apkindex_hash(url: str, length: int = 8) -> Path:
# FIXME: make config.mirrors a normal dict
# mypy: disable-error-code="literal-required"
@Cache("user_repository", "mirrors_exclude")
def urls(user_repository: bool = False, mirrors_exclude: list[str] = []) -> list[str]:
def urls(
user_repository: Path | None = None, mirrors_exclude: list[str] | Literal[True] = []
) -> list[str]:
"""Get a list of repository URLs, as they are in /etc/apk/repositories.
:param user_repository: add /mnt/pmbootstrap/packages
:param mirrors_exclude: mirrors to exclude (see pmb.core.config.Mirrors)
:param mirrors_exclude: mirrors to exclude (see pmb.core.config.Mirrors) or true to exclude
all mirrors and only return the local repos
:returns: list of mirror strings, like ["/mnt/pmbootstrap/packages",
"http://...", ...]
"""
@ -74,7 +78,10 @@ def urls(user_repository: bool = False, mirrors_exclude: list[str] = []) -> list
# Local user repository (for packages compiled with pmbootstrap)
if user_repository:
for channel in pmb.config.pmaports.all_channels():
ret.append(f"/mnt/pmbootstrap/packages/{channel}")
ret.append(str(user_repository / channel))
if mirrors_exclude is True:
return ret
# Don't add the systemd mirror if systemd is disabled
if not pmb.config.is_systemd_selected(config):