Skip to content

Commit 540a6ff

Browse files
committed
run clean on all the containers on the shared root
`ybox-pkg clean` may have container specific cache to be cleared (e.g. AUR cache for Arch Linux), so run it on all active containers on the selected shared root
1 parent 317dee3 commit 540a6ff

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

src/ybox/conf/resources/entrypoint-user.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ current_user="$(id -un)"
1010
user_home="$(getent passwd "$current_user" | cut -d: -f6)"
1111
# set gpg keyserver to an available one
1212
mkdir -p "$user_home/.gnupg" && chmod 0700 "$user_home/.gnupg"
13-
echo "keyserver $DEFAULT_GPG_KEY_SERVER" > "$user_home/.gnupg/dirmngr.conf"
13+
echo "keyserver $DEFAULT_GPG_KEY_SERVER" > "$user_home/.gnupg/dirmngr.conf" || /bin/true
1414
rm -f "$user_home"/.gnupg/*/*.lock
1515

1616
if [ ! -e "$user_home/.config/pip/pip.conf" ]; then

src/ybox/pkg/clean.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,39 @@
55
import argparse
66
from configparser import SectionProxy
77

8-
from ybox.cmd import PkgMgr, build_shell_command, run_command
8+
from ybox.cmd import (PkgMgr, build_shell_command, check_active_ybox,
9+
run_command)
910
from ybox.config import StaticConfiguration
1011
from ybox.print import print_info
12+
from ybox.state import RuntimeConfiguration, YboxStateManagement
1113

1214

15+
# noinspection PyUnusedLocal
1316
def clean_cache(args: argparse.Namespace, pkgmgr: SectionProxy, docker_cmd: str,
14-
conf: StaticConfiguration) -> int:
17+
conf: StaticConfiguration, runtime_conf: RuntimeConfiguration,
18+
state: YboxStateManagement) -> int:
19+
# pylint: disable=unused-argument
1520
"""
1621
Clean package cache and related intermediate files.
1722
18-
:param args: arguments having `quiet` and all other attributes passed by the user
23+
:param args: arguments having `package` and all other attributes passed by the user
1924
:param pkgmgr: the `[pkgmgr]` section from `distro.ini` configuration file of the distribution
2025
:param docker_cmd: the podman/docker executable to use
2126
:param conf: the :class:`StaticConfiguration` for the container
27+
:param runtime_conf: the `RuntimeConfiguration` of the container
28+
:param state: instance of `YboxStateManagement` having the state of all ybox containers
2229
:return: integer exit status of clean command where 0 represents success
2330
"""
24-
print_info(f"Cleaning package cache in container '{conf.box_name}'")
25-
clean_cmd = pkgmgr[PkgMgr.CLEAN_QUIET.value] if args.quiet else pkgmgr[PkgMgr.CLEAN.value]
26-
return int(run_command(build_shell_command(docker_cmd, conf.box_name, clean_cmd),
27-
exit_on_error=False, error_msg="cleaning package cache"))
31+
clean_cmd = pkgmgr[PkgMgr.CLEAN.value] if args.ask else pkgmgr[PkgMgr.CLEAN_QUIET.value]
32+
# run clean for each container since it can involve actions that are container specific
33+
# apart from the generic ones for the shared root (e.g. AUR cache cleaning for Arch Linux)
34+
code = 0
35+
for container in state.get_containers(shared_root=runtime_conf.shared_root):
36+
if not check_active_ybox(docker_cmd, container):
37+
continue
38+
print_info(f"Cleaning package cache in container '{container}'")
39+
if (c := int(run_command(build_shell_command(docker_cmd, container, clean_cmd),
40+
exit_on_error=False, error_msg="cleaning package cache"))) != 0:
41+
code = c
42+
print()
43+
return code

src/ybox/run/pkg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ def add_clean(subparser: argparse.ArgumentParser) -> None:
376376
377377
:param subparser: the :class:`argparse.ArgumentParser` object for the sub-command
378378
"""
379-
subparser.set_defaults(needs_state=False)
379+
subparser.add_argument("-A", "--ask", action="store_true",
380+
help="ask before each action else silently clean everything")
380381
subparser.set_defaults(group_by_shared_root=True)
381382
subparser.set_defaults(func=clean_cache)
382383

0 commit comments

Comments
 (0)