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
This commit is contained in:
parent
e1df62fdc8
commit
873defb330
1 changed files with 13 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue