import shutil
import subprocess
from pathlib import Path
-from typing import Optional, Sequence
+from typing import Optional
from mkosi.archive import extract_tar
from mkosi.config import ConfigFeature, MkosiConfig
if config.use_subvolumes == ConfigFeature.enabled and not shutil.which("btrfs"):
die("Subvolumes requested but the btrfs command was not found")
- copy: Sequence[PathString] = [
+ copy: list[PathString] = [
"cp",
"--recursive",
f"--preserve=mode,timestamps,links,xattr{',ownership' if preserve_owner else ''}",
- "--no-target-directory",
"--reflink=auto",
src, dst,
]
+ # If the source and destination are both directories, we want to merge the source directory with the
+ # destination directory. If the source if a file and the destination is a directory, we want to copy
+ # the source inside the directory.
+ if src.is_dir():
+ copy += ["--no-target-directory"]
+
# Subvolumes always have inode 256 so we can use that to check if a directory is a subvolume.
if not subvolume or not preserve_owner or not is_subvolume(src) or (dst.exists() and any(dst.iterdir())):
run(copy)