From 463e67d61c76e4aad566d3ef21437a08574afa3c Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 1 Jun 2021 19:13:25 +0200 Subject: [PATCH] api: root relative paths for stage arguments Resolve relative paths for items the `api.arguments` call: Since paths are different on the host and in the container, they can be transmitted relative. Resolve the items for all groups that have paths registered. --- osbuild/api.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/osbuild/api.py b/osbuild/api.py index bbfd49bd..d0aedfd7 100644 --- a/osbuild/api.py +++ b/osbuild/api.py @@ -249,6 +249,21 @@ def arguments(path="/run/osbuild/api/osbuild"): fd = msg["fd"] with os.fdopen(fds.steal(fd), encoding="utf-8") as f: data = json.load(f) + + # Root relative paths: since paths are different on the + # host and in the container they are transmitted not as + # absolute but relative paths. For all items that have + # registered roots, re-root their path entries here + for name, root in data.get("paths", {}).items(): + group = data.get(name) + if not group or not isinstance(group, dict): + continue + for item in group.values(): + path = item.get("path") + if not path: + continue + item["path"] = os.path.join(root, path) + return data