From: Daan De Meyer Date: Mon, 15 Apr 2024 09:53:13 +0000 (+0200) Subject: Drop support for BSD tar/cpio X-Git-Tag: v23.1~111^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e452a2c4edad6d3e49553c79a861f7d62f5855db;p=thirdparty%2Fmkosi.git Drop support for BSD tar/cpio 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. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index eee48625b..88d16ca1c 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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) diff --git a/mkosi/archive.py b/mkosi/archive.py index 32a614c04..e74a9b75b 100644 --- a/mkosi/archive.py +++ b/mkosi/archive.py @@ -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", diff --git a/mkosi/distributions/debian.py b/mkosi/distributions/debian.py index 696b16d44..f75bbf5e8 100644 --- a/mkosi/distributions/debian.py +++ b/mkosi/distributions/debian.py @@ -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.