]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use subdirectory of build directory for each subimage
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Jul 2024 08:15:36 +0000 (10:15 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Jul 2024 08:20:35 +0000 (10:20 +0200)
Instead of sharing the build directory between all images, let's
use a subdirectory of the build directory for subimages.

This requires us to unshare the user namespace in run_build() before
we create the directories so that we always have permissions to create
any nested build directories.

mkosi/__init__.py
mkosi/config.py

index 3817a09356f35700c715ffab531b1a69ca5609ae..a9b8f024f10ff2a50617831b7d6e57fcc5a2c6a3 100644 (file)
@@ -4651,6 +4651,12 @@ def run_sync(args: Args, config: Config, *, resources: Path) -> None:
 
 
 def run_build(args: Args, config: Config, *, resources: Path) -> None:
+    if (uid := os.getuid()) != 0:
+        become_root()
+    unshare(CLONE_NEWNS)
+    if uid == 0:
+        run(["mount", "--make-rslave", "/"])
+
     for p in (
         config.output_dir,
         config.cache_dir,
@@ -4664,12 +4670,6 @@ def run_build(args: Args, config: Config, *, resources: Path) -> None:
         p.mkdir(parents=True, exist_ok=True)
         INVOKING_USER.chown(p)
 
-    if (uid := os.getuid()) != 0:
-        become_root()
-    unshare(CLONE_NEWNS)
-    if uid == 0:
-        run(["mount", "--make-rslave", "/"])
-
     if config.build_dir:
         # Make sure the build directory is owned by root (in the user namespace) so that the correct uid-mapping is
         # applied if it is used in RuntimeTrees=
index 88f8b3786053c4e152646c1c685123ac52b54c53..f8abd99d53a299f74bb850f3296d63eb6245e73e 100644 (file)
@@ -3851,7 +3851,9 @@ def load_args(args: argparse.Namespace) -> Args:
 
 def load_config(config: argparse.Namespace) -> Config:
     if config.build_dir:
-        config.build_dir = config.build_dir / f"{config.distribution}~{config.release}~{config.architecture}"
+        config.build_dir /= config.build_dir / f"{config.distribution}~{config.release}~{config.architecture}"
+        if config.image:
+            config.build_dir /= config.image
 
     if config.sign:
         config.checksum = True