From: Daan De Meyer Date: Sun, 6 Aug 2023 12:13:41 +0000 (+0200) Subject: Rename mount_tools() to mount_usr() X-Git-Tag: v15~26^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae4d832c24dfaca6fda83e2c2517e3424d95a751;p=thirdparty%2Fmkosi.git Rename mount_tools() to mount_usr() And pass in the tree to use directly instead of the full config object. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index a959cc743..a927a6a4c 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -39,7 +39,7 @@ from mkosi.installer import clean_package_manager_metadata, package_manager_scri from mkosi.kmod import gen_required_kernel_modules, process_kernel_modules from mkosi.log import complete_step, die, log_step from mkosi.manifest import Manifest -from mkosi.mounts import mount_overlay, mount_passwd, mount_tools +from mkosi.mounts import mount_overlay, mount_passwd, mount_usr from mkosi.pager import page from mkosi.qemu import copy_ephemeral, run_qemu, run_ssh from mkosi.run import become_root, bwrap, chroot_cmd, init_mount_namespace, run @@ -1758,7 +1758,7 @@ def run_verb(args: MkosiArgs, presets: Sequence[MkosiConfig]) -> None: continue with complete_step(f"Building {config.preset or 'default'} image"),\ - mount_tools(config),\ + mount_usr(config.tools_tree),\ prepend_to_environ_path(config): # Create these as the invoking user to make sure they're owned by the user running mkosi. @@ -1790,7 +1790,7 @@ def run_verb(args: MkosiArgs, presets: Sequence[MkosiConfig]) -> None: # We want to drop privileges after mounting the last tools tree, but to unmount it we still need # privileges. To avoid a permission error, let's not unmount the final tools tree, since we'll exit # right after (and we're in a mount namespace so the /usr mount disappears when we exit) - with mount_tools(last, umount=False), mount_passwd(name, uid, gid, umount=False): + with mount_usr(last.tools_tree, umount=False), mount_passwd(name, uid, gid, umount=False): # After mounting the last tools tree, if we're not going to execute systemd-nspawn, we don't need to # be (fake) root anymore, so switch user to the invoking user. diff --git a/mkosi/mounts.py b/mkosi/mounts.py index df53caf5c..fbf287825 100644 --- a/mkosi/mounts.py +++ b/mkosi/mounts.py @@ -9,7 +9,7 @@ from collections.abc import Iterator, Sequence from pathlib import Path from typing import Optional, TypeVar -from mkosi.config import GenericVersion, MkosiConfig +from mkosi.config import GenericVersion from mkosi.log import complete_step from mkosi.run import run from mkosi.types import PathString @@ -98,14 +98,14 @@ def mount_overlay( @contextlib.contextmanager -def mount_tools(config: MkosiConfig, umount: bool = True) -> Iterator[None]: - if not config.tools_tree: +def mount_usr(tree: Optional[Path], umount: bool = True) -> Iterator[None]: + if not tree: yield return - # If a tools tree is specified, we should ignore any local modifications made to PATH as any of those - # binaries might not work anymore when /usr is replaced wholesale. We also make sure that both /usr/bin - # and /usr/sbin/ are searched so that e.g. if the host is Arch and the root is Debian we don't ignore the + # If we replace /usr, we should ignore any local modifications made to PATH as any of those binaries + # might not work anymore when /usr is replaced wholesale. We also make sure that both /usr/bin and + # /usr/sbin/ are searched so that e.g. if the host is Arch and the root is Debian we don't ignore the # binaries from /usr/sbin in the Debian root. old = os.environ["PATH"] os.environ["PATH"] = "/usr/bin:/usr/sbin" @@ -114,7 +114,7 @@ def mount_tools(config: MkosiConfig, umount: bool = True) -> Iterator[None]: # If we mounted over /usr, trying to use umount will fail with "target is busy", because umount is # being called from /usr, which we're trying to unmount. To work around this issue, we do a lazy # unmount. - with mount(what=config.tools_tree / "usr", where=Path("/usr"), operation="--bind", read_only=True, umount=umount, lazy=True): + with mount(what=tree / "usr", where=Path("/usr"), operation="--bind", read_only=True, umount=umount, lazy=True): yield finally: os.environ["PATH"] = old