]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't unpack extra/skeleton archives if a target is provided 1615/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 7 Jun 2023 12:01:51 +0000 (14:01 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 7 Jun 2023 12:01:51 +0000 (14:01 +0200)
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

index c8bd9b09e5b96f7d35bac3a9884a5bea66e76414..68ae82f1234f96ea4b7e7a35409b7d8f9dd81240 100644 (file)
@@ -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)