]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't rely on /tmp being mounted into the sandbox
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Jan 2024 13:49:04 +0000 (14:49 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Jan 2024 14:33:43 +0000 (15:33 +0100)
Let's not rely on /tmp implicitly being mounted in the sandbox.

mkosi/distributions/debian.py
mkosi/installer/apt.py

index 1cc98cf632b317b09c8f09d079bcedcafb6df6ca..89d89c2ff5baf3ca62e3cf382d9fc8f65db9f11a 100644 (file)
@@ -109,17 +109,26 @@ class Installer(DistributionInstaller):
                 (context.root / d).symlink_to(f"usr/{d}")
                 (context.root / f"usr/{d}").mkdir(parents=True, exist_ok=True)
 
+        invoke_apt(context, "apt-get", "update", apivfs=False)
+
         # Next, we invoke apt-get install to download all the essential packages. With DPkg::Pre-Install-Pkgs,
         # we specify a shell command that will receive the list of packages that will be installed on stdin.
         # By configuring Debug::pkgDpkgPm=1, apt-get install will not actually execute any dpkg commands, so
         # all it does is download the essential debs and tell us their full in the apt cache without actually
         # installing them.
-        with tempfile.NamedTemporaryFile(dir="/tmp", mode="r") as f:
-            cls.install_packages(context, [
-                "-oDebug::pkgDPkgPm=1",
-                f"-oDPkg::Pre-Install-Pkgs::=cat >{f.name}",
-                "?essential", "?name(usr-is-merged)",
-            ], apivfs=False)
+        with tempfile.NamedTemporaryFile(mode="r") as f:
+            invoke_apt(
+                context,
+                "apt-get",
+                "install",
+                [
+                    "-oDebug::pkgDPkgPm=1",
+                    f"-oDPkg::Pre-Install-Pkgs::=cat >{f.name}",
+                    "?essential", "?name(usr-is-merged)",
+                ],
+                apivfs=False,
+                mounts=("--bind", f.name, f.name),
+            )
 
             essential = f.read().strip().splitlines()
 
index 5be99e4a4f058f2a88451ced9595ad677f677c4b..496e25675fd633c018a93762a7e4f234d4e60404 100644 (file)
@@ -96,7 +96,9 @@ def invoke_apt(
     command: str,
     operation: str,
     packages: Sequence[str] = (),
+    *,
     apivfs: bool = True,
+    mounts: Sequence[PathString] = (),
 ) -> None:
     run(
         apt_cmd(context, command) + [operation, *sort_packages(packages)],
@@ -108,6 +110,7 @@ def invoke_apt(
                     "--bind", context.cache_dir, context.cache_dir,
                     "--ro-bind", context.workspace / "apt.conf", context.workspace / "apt.conf",
                     *finalize_crypto_mounts(tools=context.config.tools()),
+                    *mounts,
                 ],
             ) + (apivfs_cmd(context.root, tools=context.config.tools()) if apivfs else [])
         ),