From: Daan De Meyer Date: Sun, 6 Aug 2023 13:10:07 +0000 (+0200) Subject: Only set --no-target-directory for cp when src is a directory X-Git-Tag: v15~26^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ef5c6ea15a66872a5b63a7096ac3319e38bb7bb;p=thirdparty%2Fmkosi.git Only set --no-target-directory for cp when src is a directory This makes sure that when src is a file and dst is a directory that src is copied into dst. --- diff --git a/mkosi/tree.py b/mkosi/tree.py index 06e011986..952c75646 100644 --- a/mkosi/tree.py +++ b/mkosi/tree.py @@ -4,7 +4,7 @@ import errno 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 @@ -50,15 +50,20 @@ def copy_tree(config: MkosiConfig, src: Path, dst: Path, *, preserve_owner: bool 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)