]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Drop support for BSD tar/cpio
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 15 Apr 2024 09:53:13 +0000 (11:53 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 15 Apr 2024 09:53:13 +0000 (11:53 +0200)
Let's drop this compat kludge for OpenMandriva. No other distro
does this and we should just assume gnu tar/cpio as the official
API of the tar/cpio binaries.

mkosi/__init__.py
mkosi/archive.py
mkosi/distributions/debian.py

index eee48625bf7af73640ac2e8b67e83f3dc3f4d074..88d16ca1cbb8852896baa02092ccf475f9e885dc 100644 (file)
@@ -104,7 +104,7 @@ def mount_base_trees(context: Context) -> Iterator[None]:
             if path.is_dir():
                 bases += [path]
             elif path.suffix == ".tar":
-                extract_tar(path, d, tools=context.config.tools(), sandbox=context.sandbox)
+                extract_tar(path, d, sandbox=context.sandbox)
                 bases += [d]
             elif path.suffix == ".raw":
                 run(["systemd-dissect", "-M", path, d])
@@ -1503,7 +1503,7 @@ def install_tree(
     if src.is_dir() or (src.is_file() and target):
         copy()
     elif src.suffix == ".tar":
-        extract_tar(src, t, tools=config.tools(), sandbox=config.sandbox)
+        extract_tar(src, t, sandbox=config.sandbox)
     elif src.suffix == ".raw":
         run(
             ["systemd-dissect", "--copy-from", src, "/", t],
@@ -1865,7 +1865,7 @@ def build_microcode_initrd(context: Context) -> Optional[Path]:
                 for p in intel.iterdir():
                     f.write(p.read_bytes())
 
-    make_cpio(root, microcode, tools=context.config.tools(), sandbox=context.sandbox)
+    make_cpio(root, microcode, sandbox=context.sandbox)
 
     return microcode
 
@@ -1884,7 +1884,6 @@ def build_kernel_modules_initrd(context: Context, kver: str) -> Path:
             host=context.config.kernel_modules_initrd_include_host,
             sandbox=context.sandbox,
         ),
-        tools=context.config.tools(),
         sandbox=context.sandbox,
     )
 
@@ -2343,7 +2342,7 @@ def install_kernel(context: Context, partitions: Sequence[Partition]) -> None:
 
 
 def make_uki(context: Context, stub: Path, kver: str, kimg: Path, microcode: Optional[Path], output: Path) -> None:
-    make_cpio(context.root, context.workspace / "initrd", tools=context.config.tools(), sandbox=context.sandbox)
+    make_cpio(context.root, context.workspace / "initrd", sandbox=context.sandbox)
     maybe_compress(context, context.config.compress_output, context.workspace / "initrd", context.workspace / "initrd")
 
     initrds = [microcode] if microcode else []
@@ -3654,28 +3653,16 @@ def build_image(context: Context) -> None:
     copy_initrd(context)
 
     if context.config.output_format == OutputFormat.tar:
-        make_tar(
-            context.root, context.staging / context.config.output_with_format,
-            tools=context.config.tools(),
-            sandbox=context.sandbox,
-        )
+        make_tar(context.root, context.staging / context.config.output_with_format, sandbox=context.sandbox)
     elif context.config.output_format == OutputFormat.oci:
-        make_tar(
-            context.root, context.staging / "rootfs.layer",
-            tools=context.config.tools(),
-            sandbox=context.sandbox,
-        )
+        make_tar(context.root, context.staging / "rootfs.layer", sandbox=context.sandbox)
         make_oci(
             context,
             context.staging / "rootfs.layer",
             context.staging / context.config.output_with_format,
         )
     elif context.config.output_format == OutputFormat.cpio:
-        make_cpio(
-            context.root, context.staging / context.config.output_with_format,
-            tools=context.config.tools(),
-            sandbox=context.sandbox,
-        )
+        make_cpio(context.root, context.staging / context.config.output_with_format, sandbox=context.sandbox)
     elif context.config.output_format == OutputFormat.uki:
         assert stub and kver and kimg
         make_uki(context, stub, kver, kimg, microcode, context.staging / context.config.output_with_format)
index 32a614c049406bb2ddc9d146abd5e433b2b7c2f3..e74a9b75beae69f8603e0d96ae8693e0d265494c 100644 (file)
@@ -6,26 +6,11 @@ from pathlib import Path
 from typing import Optional
 
 from mkosi.log import log_step
-from mkosi.run import find_binary, run
+from mkosi.run import run
 from mkosi.sandbox import Mount, SandboxProtocol, finalize_passwd_mounts, nosandbox
 from mkosi.util import umask
 
 
-def tar_binary(*, tools: Path = Path("/")) -> str:
-    # Some distros (Mandriva) install BSD tar as "tar", hence prefer
-    # "gtar" if it exists, which should be GNU tar wherever it exists.
-    # We are interested in exposing same behaviour everywhere hence
-    # it's preferable to use the same implementation of tar
-    # everywhere. In particular given the limited/different SELinux
-    # support in BSD tar and the different command line syntax
-    # compared to GNU tar.
-    return "gtar" if find_binary("gtar", root=tools) else "tar"
-
-
-def cpio_binary(*, tools: Path = Path("/")) -> str:
-    return "gcpio" if find_binary("gcpio", root=tools) else "cpio"
-
-
 def tar_exclude_apivfs_tmp() -> list[str]:
     return [
         "--exclude", "./dev/*",
@@ -37,13 +22,13 @@ def tar_exclude_apivfs_tmp() -> list[str]:
     ]
 
 
-def make_tar(src: Path, dst: Path, *, tools: Path = Path("/"), sandbox: SandboxProtocol = nosandbox) -> None:
+def make_tar(src: Path, dst: Path, *, sandbox: SandboxProtocol = nosandbox) -> None:
     log_step(f"Creating tar archive {dst}…")
 
     with dst.open("wb") as f:
         run(
             [
-                tar_binary(tools=tools),
+                "tar",
                 "--create",
                 "--file", "-",
                 "--directory", src,
@@ -70,7 +55,6 @@ def extract_tar(
     dst: Path,
     *,
     log: bool = True,
-    tools: Path = Path("/"),
     sandbox: SandboxProtocol = nosandbox,
 ) -> None:
     if log:
@@ -82,7 +66,7 @@ def extract_tar(
     with src.open("rb") as f:
         run(
             [
-                tar_binary(tools=tools),
+                "tar",
                 "--extract",
                 "--file", "-",
                 "--directory", dst,
@@ -110,7 +94,6 @@ def make_cpio(
     dst: Path,
     *,
     files: Optional[Iterable[Path]] = None,
-    tools: Path = Path("/"),
     sandbox: SandboxProtocol = nosandbox,
 ) -> None:
     if not files:
@@ -122,7 +105,7 @@ def make_cpio(
     with dst.open("wb") as f:
         run(
             [
-                cpio_binary(tools=tools),
+                "cpio",
                 "--create",
                 "--reproducible",
                 "--null",
index 696b16d44207e3bfe827cb2b8d3867f2dad2ce80..f75bbf5e8b44dd487e44a8aa6d6c00bf8c9843e3 100644 (file)
@@ -176,12 +176,7 @@ class Installer(DistributionInstaller):
 
             with open(path, "rb") as i, tempfile.NamedTemporaryFile() as o:
                 run(["dpkg-deb", "--fsys-tarfile", "/dev/stdin"], stdin=i, stdout=o, sandbox=context.sandbox())
-                extract_tar(
-                    Path(o.name), context.root,
-                    log=False,
-                    tools=context.config.tools(),
-                    sandbox=context.sandbox,
-                )
+                extract_tar(Path(o.name), context.root, log=False, sandbox=context.sandbox)
 
         # Finally, run apt to properly install packages in the chroot without having to worry that maintainer
         # scripts won't find basic tools that they depend on.