From df663ada8a4c49b81dbeb22abf8ea831bcf4901c Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Tue, 30 Jan 2024 16:06:31 +0100 Subject: [PATCH] stages(tar): add paths option This adds an optional `paths` option to the tar stage. If specified, the paths will be included in the tarball in order. The OVA image needs to have its contents in a specific order in the archive. --- stages/org.osbuild.tar | 44 +++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/stages/org.osbuild.tar b/stages/org.osbuild.tar index f42ccd9d..4068c551 100755 --- a/stages/org.osbuild.tar +++ b/stages/org.osbuild.tar @@ -26,6 +26,25 @@ CAPABILITIES = ["CAP_MAC_ADMIN"] SCHEMA_2 = """ "options": { "additionalProperties": false, + "anyOf": [ + { + "required": ["root-node"], + "not": { + "required": ["paths"] + } + }, + { + "required": ["paths"], + "not": { + "required": ["root-node"] + } + }, + { + "not": { + "required": ["paths", "root-node"] + } + } + ], "required": ["filename"], "properties": { "filename": { @@ -54,8 +73,15 @@ SCHEMA_2 = """ "default": true }, "root-node": { - "description": "How to handle the root node: include or omit", + "description": "How to handle the root node: include or omit, mutually exclusive with paths", "enum": ["include", "omit"] + }, + "paths": { + "type": "array", + "items": { + "type": "string", + "description": "If specified, the archive will only contain the specified paths, in the specified order" + } } } }, @@ -78,6 +104,7 @@ def main(inputs, output_dir, options): filename = options["filename"].lstrip("/") tarfmt = options.get("format", "gnu") root_node = options.get("root-node", "include") + paths = options.get("paths", []) extra_args = [] # Set environment variables for the tar operation. @@ -106,13 +133,16 @@ def main(inputs, output_dir, options): "-C", tree, ] - # Should we include the root inode or not - # This will change the way files are listed: - # `./file` (include) vs `file` (omit) - if root_node == "include": - tar_cmd += ["."] + if len(paths) == 0: + # Should we include the root inode or not + # This will change the way files are listed: + # `./file` (include) vs `file` (omit) + if root_node == "include": + tar_cmd += ["."] + else: + tar_cmd += os.listdir(tree) else: - tar_cmd += os.listdir(tree) + tar_cmd += paths # Make a tarball of the tree. subprocess.run(