From 873defb330d955f4e9d1859a8b46eeb565cb350c Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 22 Jul 2021 10:31:27 +0000 Subject: [PATCH] stages/tar: option to not include the root node When building the tar archive, the command that is used normally includes the root node as `./` and also leads to all files having a "./" prefix. On the other hand, the oci stage as well as the old ostree.commit assembler, with the tarball option, would enumerate the contents instead of passing `.`, thus not including the rood node and also avoiding the `./` prefix. Add a new option `root-node` that controls whether the rood node is included or node. mkdir test touch test/file tar -c -C test file | tar tv -rw-r--r-- root/root 0 2021-07-22 10:39 file tar -c -C test . | tar tv drwxr-xr-x root/root 0 2021-07-22 10:39 ./ -rw-r--r-- root/root 0 2021-07-22 10:39 ./file --- stages/org.osbuild.tar | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/stages/org.osbuild.tar b/stages/org.osbuild.tar index 8abde832..76c834b2 100755 --- a/stages/org.osbuild.tar +++ b/stages/org.osbuild.tar @@ -50,6 +50,10 @@ SCHEMA_2 = """ "description": "Enable support for extended attributes", "type": "boolean", "default": true + }, + "root-node": { + "description": "How to handle the root node: include or omit", + "enum": ["include", "omit"] } } }, @@ -71,6 +75,7 @@ def main(inputs, output_dir, options): tree = inputs["tree"]["path"] filename = options["filename"].lstrip("/") tarfmt = options.get("format", "gnu") + root_node = options.get("root-node", "include") extra_args = [] # Set environment variables for the tar operation. @@ -97,9 +102,16 @@ def main(inputs, output_dir, options): *extra_args, "-cf", os.path.join(output_dir, filename), "-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 += ["."] + else: + tar_cmd += os.listdir(tree) + # Make a tarball of the tree. subprocess.run( tar_cmd,