]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Rename mount_tools() to mount_usr()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 6 Aug 2023 12:13:41 +0000 (14:13 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 6 Aug 2023 12:13:41 +0000 (14:13 +0200)
And pass in the tree to use directly instead of the full config
object.

mkosi/__init__.py
mkosi/mounts.py

index a959cc74396cab41f475b9adef6c7f19908d62be..a927a6a4c53efecb63cd2eaa125747a35a52987c 100644 (file)
@@ -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.
index df53caf5c3e05c54f940196bad3f68a94c6a4203..fbf2878255c3282deed8b02239df37fe0a1e1af0 100644 (file)
@@ -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