]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-tar-extract: add a binary wrapping tar_x() for manual testing
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 15 Oct 2025 09:42:41 +0000 (11:42 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 16 Oct 2025 06:22:33 +0000 (08:22 +0200)
We'll probably want to turn this into a test in the integration tests.

src/import/meson.build
src/import/test-tar-extract.c [new file with mode: 0644]

index e1670da8174d81986db7dc25358554aee9bc6cf6..4aec57373affa93bfeda611c84bd10e6c572d2fd 100644 (file)
@@ -93,6 +93,10 @@ executables += [
                 'name' : 'systemd-import-generator',
                 'sources' : files('import-generator.c'),
         },
+        test_template + {
+                'sources' : files('test-tar-extract.c'),
+                'type' : 'manual',
+        },
         test_template + {
                 'sources' : files('test-qcow2.c'),
                 'objects' : ['systemd-importd'],
@@ -100,6 +104,7 @@ executables += [
                 'conditions' : ['HAVE_ZLIB'],
                 'type' : 'manual',
         },
+
 ]
 
 install_data('org.freedesktop.import1.conf',
diff --git a/src/import/test-tar-extract.c b/src/import/test-tar-extract.c
new file mode 100644 (file)
index 0000000..f7fa06f
--- /dev/null
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "fd-util.h"
+#include "libarchive-util.h"
+#include "main-func.h"
+#include "tar-util.h"
+#include "tests.h"
+
+static int run(int argc, char **argv) {
+        int r;
+
+        test_setup_logging(LOG_DEBUG);
+
+        if (argc != 3)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Need two arguments exactly: <input> <output>");
+
+        r = dlopen_libarchive();
+        if (r < 0)
+                return r;
+
+        _cleanup_close_ int input_fd = open(argv[1], O_RDONLY | O_CLOEXEC);
+        if (input_fd < 0)
+                return log_error_errno(input_fd, "Cannot open %s: %m", argv[1]);
+
+        _cleanup_close_ int output_fd = open(argv[2], O_DIRECTORY | O_CLOEXEC);
+        if (output_fd < 0)
+                return log_error_errno(output_fd, "Cannot open %s: %m", argv[2]);
+
+        r = tar_x(input_fd, output_fd, /* flags= */ TAR_SELINUX);
+        if (r < 0)
+                return log_error_errno(r, "tar_x failed: %m");
+
+        return 0;
+}
+
+DEFINE_MAIN_FUNCTION(run);