From: Daan De Meyer Date: Wed, 9 Aug 2023 08:01:46 +0000 (+0200) Subject: Prefer gcpio over cpio X-Git-Tag: v15~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=373623d75e69ac9c83462caf33fd436e507afa3f;p=thirdparty%2Fmkosi.git Prefer gcpio over cpio Fixes #1201 --- diff --git a/mkosi/archive.py b/mkosi/archive.py index ca26e7768..07e9634ee 100644 --- a/mkosi/archive.py +++ b/mkosi/archive.py @@ -1,13 +1,28 @@ # SPDX-License-Identifier: LGPL-2.1+ import os +import shutil from collections.abc import Iterable from pathlib import Path from typing import Optional from mkosi.log import log_step from mkosi.run import bwrap, finalize_passwd_mounts -from mkosi.util import tar_binary + + +def tar_binary() -> 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 shutil.which("gtar") else "tar" + + +def cpio_binary() -> str: + return "gcpio" if shutil.which("gcpio") else "cpio" def tar_exclude_apivfs_tmp() -> list[str]: @@ -74,7 +89,7 @@ def make_cpio(src: Path, dst: Path, files: Optional[Iterable[Path]] = None) -> N log_step(f"Creating cpio archive {dst}…") bwrap( [ - "cpio", + cpio_binary(), "--create", "--reproducible", "--null", diff --git a/mkosi/util.py b/mkosi/util.py index 4ebfed847..88a329f82 100644 --- a/mkosi/util.py +++ b/mkosi/util.py @@ -14,7 +14,6 @@ import os import pwd import re import resource -import shutil import stat import sys import tempfile @@ -223,17 +222,6 @@ class StrEnum(enum.Enum): return list(map(str, cls)) -def tar_binary() -> 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 shutil.which("gtar") else "tar" - - def one_zero(b: bool) -> str: return "1" if b else "0"