From: Daan De Meyer Date: Thu, 14 Dec 2023 15:30:02 +0000 (+0100) Subject: Fix install_tree() X-Git-Tag: v20~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=946fcbcb3eeac04d07901174596401a9c31a8462;p=thirdparty%2Fmkosi.git Fix install_tree() Let's make sure that all the skeleton, extra and package manager trees we get have absolute targets. That allows us to stop using with_prefix() when installing these trees, which means we pass target=None instead of target="/" which makes install_tree do the right thing. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index aefff3eab..6e714681e 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1227,8 +1227,7 @@ def install_skeleton_trees(state: MkosiState) -> None: with complete_step("Copying in skeleton file trees…"): for tree in state.config.skeleton_trees: - source, target = tree.with_prefix() - install_tree(source, state.root, target, use_subvolumes=state.config.use_subvolumes) + install_tree(tree.source, state.root, tree.target, use_subvolumes=state.config.use_subvolumes) def install_package_manager_trees(state: MkosiState) -> None: @@ -1237,8 +1236,12 @@ def install_package_manager_trees(state: MkosiState) -> None: with complete_step("Copying in package manager file trees…"): for tree in state.config.package_manager_trees: - source, target = tree.with_prefix() - install_tree(source, state.workspace / "pkgmngr", target, use_subvolumes=state.config.use_subvolumes) + install_tree( + tree.source, + state.workspace / "pkgmngr", + tree.target, + use_subvolumes=state.config.use_subvolumes + ) def install_extra_trees(state: MkosiState) -> None: @@ -1247,8 +1250,7 @@ def install_extra_trees(state: MkosiState) -> None: with complete_step("Copying in extra file trees…"): for tree in state.config.extra_trees: - source, target = tree.with_prefix() - install_tree(source, state.root, target, use_subvolumes=state.config.use_subvolumes) + install_tree(tree.source, state.root, tree.target, use_subvolumes=state.config.use_subvolumes) def install_build_dest(state: MkosiState) -> None: diff --git a/mkosi/config.py b/mkosi/config.py index 631eb6b72..c733ef879 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -241,7 +241,8 @@ def parse_path(value: str, executable: bool = False, expanduser: bool = True, expandvars: bool = True, - secret: bool = False) -> Path: + secret: bool = False, + absolute: bool = False) -> Path: if expandvars: value = os.path.expandvars(value) @@ -255,6 +256,9 @@ def parse_path(value: str, if required and not path.exists(): die(f"{value} does not exist") + if absolute and not path.is_absolute(): + die(f"{value} must be an absolute path") + if resolve: path = path.resolve() @@ -272,13 +276,22 @@ def parse_path(value: str, return path -def parse_tree(value: str) -> ConfigTree: - src, sep, tgt = value.partition(':') +def make_tree_parser(absolute: bool = True) -> Callable[[str], ConfigTree]: + def parse_tree(value: str) -> ConfigTree: + src, sep, tgt = value.partition(':') - return ConfigTree( - source=parse_path(src, required=False), - target=parse_path(tgt, required=False, resolve=False, expanduser=False) if sep else None, - ) + return ConfigTree( + source=parse_path(src, required=False), + target=parse_path( + tgt, + required=False, + resolve=False, + expanduser=False, + absolute=absolute, + ) if sep else None, + ) + + return parse_tree def config_match_build_sources(match: str, value: list[ConfigTree]) -> bool: @@ -1349,7 +1362,7 @@ SETTINGS = ( long="--package-manager-tree", metavar="PATH", section="Distribution", - parse=config_make_list_parser(delimiter=",", parse=parse_tree), + parse=config_make_list_parser(delimiter=",", parse=make_tree_parser()), default_factory=lambda ns: ns.skeleton_trees, default_factory_depends=("skeleton_trees",), help="Use a package manager tree to configure the package manager", @@ -1550,7 +1563,7 @@ SETTINGS = ( long="--skeleton-tree", metavar="PATH", section="Content", - parse=config_make_list_parser(delimiter=",", parse=parse_tree), + parse=config_make_list_parser(delimiter=",", parse=make_tree_parser()), paths=("mkosi.skeleton", "mkosi.skeleton.tar"), path_default=False, help="Use a skeleton tree to bootstrap the image before installing anything", @@ -1560,7 +1573,7 @@ SETTINGS = ( long="--extra-tree", metavar="PATH", section="Content", - parse=config_make_list_parser(delimiter=",", parse=parse_tree), + parse=config_make_list_parser(delimiter=",", parse=make_tree_parser()), paths=("mkosi.extra", "mkosi.extra.tar"), path_default=False, help="Copy an extra tree on top of image", @@ -1645,7 +1658,7 @@ SETTINGS = ( dest="build_sources", metavar="PATH", section="Content", - parse=config_make_list_parser(delimiter=",", parse=parse_tree), + parse=config_make_list_parser(delimiter=",", parse=make_tree_parser(absolute=False)), match=config_match_build_sources, help="Path for sources to build", ), @@ -2170,7 +2183,7 @@ SETTINGS = ( long="--runtime-tree", metavar="SOURCE:[TARGET]", section="Host", - parse=config_make_list_parser(delimiter=",", parse=parse_tree), + parse=config_make_list_parser(delimiter=",", parse=make_tree_parser(absolute=False)), help="Additional mounts to add when booting the image", ), MkosiConfigSetting( diff --git a/mkosi/tree.py b/mkosi/tree.py index a35c6abdc..3d8363df8 100644 --- a/mkosi/tree.py +++ b/mkosi/tree.py @@ -145,4 +145,5 @@ def install_tree( elif src.suffix == ".raw": run(["systemd-dissect", "--copy-from", src, "/", t]) else: - die(f"Source tree {src} has unsupported source tree type \"{src.suffix}\"") + # If we get an unknown file without a target, we just copy it into /. + copy_tree(src, t, preserve_owner=False, use_subvolumes=use_subvolumes)