From 304f2212f6a130c2af3fa7f4a29f17e77d666aa0 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 7 Jun 2023 14:01:51 +0200 Subject: [PATCH] Don't unpack extra/skeleton archives if a target is provided ExtraTrees= and SkeletonTrees= are currently ambiguous when a target location is provided. The user could either mean that the archive has to be unpacked to the target location or the user could mean that he wants to copy the archive to that location in the image. We should still try to resolve the ambiguity, but for now, let's assume that when a target is provided that the user wants to copy the archive into the image instead of unpacking the archive to that specific location. To make this work, we also modify the logic slightly to create only the parent directories of the target so that cp doesn't fail because we try to copy a file to a directory. --- mkosi/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index c8bd9b09e..68ae82f12 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -515,8 +515,9 @@ def install_skeleton_trees(state: MkosiState) -> None: if target: t = state.root / target.relative_to("/") - t.mkdir(mode=0o755, parents=True, exist_ok=True) - if source.is_dir(): + t.parent.mkdir(mode=0o755, parents=True, exist_ok=True) + + if source.is_dir() or target: copy_path(source, t, preserve_owner=False) else: shutil.unpack_archive(source, t) @@ -532,9 +533,9 @@ def install_extra_trees(state: MkosiState) -> None: if target: t = state.root / target.relative_to("/") - t.mkdir(mode=0o755, parents=True, exist_ok=True) + t.parent.mkdir(mode=0o755, parents=True, exist_ok=True) - if source.is_dir(): + if source.is_dir() or target: copy_path(source, t, preserve_owner=False) else: shutil.unpack_archive(source, t) -- 2.47.2