From 7709b7caeb14c122d6ef50b9cae0af6be0701a7f Mon Sep 17 00:00:00 2001 From: Luke Yang Date: Mon, 26 Feb 2024 16:10:11 -0500 Subject: [PATCH] stages/org.osbuild.tar: add sparse option Add a sparse option to the tar stage which make files in the archive sparse if they are sparse on disk. This is needed for CoreOS Assember. --- stages/org.osbuild.tar | 10 +++++++++- stages/test/test_tar.py | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/stages/org.osbuild.tar b/stages/org.osbuild.tar index 4068c551..2c53e637 100755 --- a/stages/org.osbuild.tar +++ b/stages/org.osbuild.tar @@ -82,6 +82,11 @@ SCHEMA_2 = """ "type": "string", "description": "If specified, the archive will only contain the specified paths, in the specified order" } + }, + "sparse": { + "description": "Make archive files sparse", + "type": "boolean", + "default": false } } }, @@ -113,7 +118,7 @@ def main(inputs, output_dir, options): "XZ_OPT": "--threads 0" } - # SELinux context, ACLs and extended attributes + # SELinux context, ACLs, extended attributes, and sparse if options.get("acls", True): extra_args += ["--acls"] @@ -123,6 +128,9 @@ def main(inputs, output_dir, options): if options.get("xattrs", True): extra_args += ["--xattrs", "--xattrs-include", "*"] + if options.get("sparse", False): + extra_args += ["--sparse"] + # Set up the tar command. tar_cmd = [ "tar", diff --git a/stages/test/test_tar.py b/stages/test/test_tar.py index 6a988a69..10db07ab 100644 --- a/stages/test/test_tar.py +++ b/stages/test/test_tar.py @@ -22,6 +22,7 @@ STAGE_NAME = "org.osbuild.tar" # good ({"filename": "out.tar", "root-node": "include"}, ""), ({"filename": "out.tar", "paths": ["file1"]}, ""), + ({"filename": "out.tar", "sparse": True}, ""), ({"filename": "out.tar"}, ""), ]) def test_schema_validation_tar(stage_schema, test_data, expected_err):