from pathlib import Path
from typing import Optional, Union, cast
-from mkosi.archive import extract_tar, make_cpio, make_tar
+from mkosi.archive import can_extract_tar, extract_tar, make_cpio, make_tar
from mkosi.burn import run_burn
from mkosi.config import (
Args,
if path.is_dir():
bases += [path]
- elif path.suffix == ".tar":
+ elif can_extract_tar(path):
extract_tar(path, d, sandbox=context.sandbox)
bases += [d]
elif path.suffix == ".raw":
if src.is_dir() or (src.is_file() and target):
copy()
- elif src.suffix == ".tar":
+ elif can_extract_tar(src):
extract_tar(src, t, sandbox=config.sandbox)
elif src.suffix == ".raw":
run(
)
+def can_extract_tar(src: Path) -> bool:
+ return ".tar" in src.suffixes[-2:]
+
+
def extract_tar(
src: Path,
dst: Path,
with umask(~0o755):
dst.mkdir(exist_ok=True)
- with src.open("rb") as f:
- run(
- [
- "tar",
- "--extract",
- "--file", "-",
- "--directory", dst,
- "--keep-directory-symlink",
- "--no-overwrite-dir",
- "--same-permissions",
- "--same-owner" if (dst / "etc/passwd").exists() else "--numeric-owner",
- "--same-order",
- "--acls",
- "--selinux",
- "--xattrs",
- "--force-local",
- *tar_exclude_apivfs_tmp(),
- ],
- stdin=f,
- sandbox=sandbox(
- binary="tar",
- # Make sure tar uses user/group information from the root directory instead of the host.
- mounts=[Mount(src, src, ro=True), Mount(dst, dst), *finalize_passwd_mounts(dst)]
- ),
- )
+ run(
+ [
+ "tar",
+ "--extract",
+ "--file", src,
+ "--directory", dst,
+ "--keep-directory-symlink",
+ "--no-overwrite-dir",
+ "--same-permissions",
+ "--same-owner" if (dst / "etc/passwd").exists() else "--numeric-owner",
+ "--same-order",
+ "--acls",
+ "--selinux",
+ "--xattrs",
+ "--force-local",
+ *tar_exclude_apivfs_tmp(),
+ ],
+ sandbox=sandbox(
+ binary="tar",
+ # Make sure tar uses user/group information from the root directory instead of the host.
+ mounts=[Mount(src, src, ro=True), Mount(dst, dst), *finalize_passwd_mounts(dst)]
+ ),
+ )
def make_cpio(