helpers: apk: sanity check final command (MR 2463)

When running "apk add" we must always have --cache-dir set! We also
expect --no-interactive to be set.

Add some asserts so we don't regress here.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-10-28 02:33:28 +01:00
parent 7847488058
commit 41c8413fda
No known key found for this signature in database
GPG key ID: 0583312B195F64B6

View file

@ -205,6 +205,18 @@ def run(command: Sequence[PathString], chroot: Chroot, with_progress: bool = Tru
"""
_command = _prepare_cmd(command, chroot)
# Sanity checks. We should avoid accidentally writing to
# /var/cache/apk on the host!
if "add" in command:
if "--no-interactive" not in _command:
raise RuntimeError(
"Encountered an 'apk add' command without --no-interactive! This is a bug."
)
if "--cache-dir" not in _command:
raise RuntimeError(
"Encountered an 'apk add' command without --cache-dir! This is a bug."
)
if with_progress:
_apk_with_progress(_command)
else: