]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Test tar --gid --gname --uid --uname options
authorTim Kientzle <kientzle@gmail.com>
Sun, 2 May 2010 06:33:00 +0000 (02:33 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sun, 2 May 2010 06:33:00 +0000 (02:33 -0400)
Fix a couple of bugs they uncovered.

SVN-Revision: 2358

Makefile.am
tar/test/CMakeLists.txt
tar/test/test_option_gid_gname.c [new file with mode: 0644]
tar/test/test_option_uid_uname.c [new file with mode: 0644]
tar/write.c

index 573ea7b13941850feb3c314883507ae25c8ed148..e2e8f577141278b29cc00f8c45c202850e4ca9b7 100644 (file)
@@ -497,12 +497,14 @@ bsdtar_test_SOURCES=                                              \
        tar/test/test_option_X_upper.c                          \
        tar/test/test_option_b.c                                \
        tar/test/test_option_exclude.c                          \
+       tar/test/test_option_gid_gname.c                        \
        tar/test/test_option_k.c                                \
        tar/test/test_option_keep_newer_files.c                 \
        tar/test/test_option_n.c                                \
        tar/test/test_option_q.c                                \
        tar/test/test_option_r.c                                \
        tar/test/test_option_s.c                                \
+       tar/test/test_option_uid_uname.c                        \
        tar/test/test_patterns.c                                \
        tar/test/test_stdio.c                                   \
        tar/test/test_strip_components.c                        \
index c95222f3c3a6db87c6721863afa15ddd63c6cbde..ee2134c23c5f8d4d0411383f3be59d4479eb3823 100644 (file)
@@ -23,12 +23,14 @@ IF(ENABLE_TAR AND ENABLE_TEST)
     test_option_X_upper.c
     test_option_b.c
     test_option_exclude.c
+    test_option_gid_gname.c
     test_option_k.c
     test_option_keep_newer_files.c
     test_option_n.c
     test_option_q.c
     test_option_r.c
     test_option_s.c
+    test_option_uid_uname.c
     test_patterns.c
     test_stdio.c
     test_strip_components.c
diff --git a/tar/test/test_option_gid_gname.c b/tar/test/test_option_gid_gname.c
new file mode 100644 (file)
index 0000000..7a1dc6d
--- /dev/null
@@ -0,0 +1,80 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_gid_gname)
+{
+       char *reference, *data;
+       size_t s;
+
+       assertUmask(0);
+       assertMakeFile("file", 0644, "1234567890");
+
+       /* Create archive with no special options. */
+       failure("Error invoking %s c", testprog);
+       assertEqualInt(0,
+           systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt",
+               testprog));
+       assertEmptyFile("stdout1.txt");
+       assertEmptyFile("stderr1.txt");
+       reference = slurpfile(&s, "archive1");
+
+       /* Again with both --gid and --gname */
+       failure("Error invoking %s c", testprog);
+       assertEqualInt(0,
+           systemf("%s cf archive2 --gid=17 --gname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt",
+               testprog));
+       assertEmptyFile("stdout2.txt");
+       assertEmptyFile("stderr2.txt");
+       data = slurpfile(&s, "archive2");
+       /* Should force gid and gname fields in ustar header. */
+       assertEqualMem(data + 116, "000021 \0", 8);
+       assertEqualMem(data + 297, "foofoofoo\0", 10);
+
+       /* Again with just --gid */
+       failure("Error invoking %s c", testprog);
+       assertEqualInt(0,
+           systemf("%s cf archive3 --gid=17 --format=ustar file >stdout3.txt 2>stderr3.txt",
+               testprog));
+       assertEmptyFile("stdout3.txt");
+       assertEmptyFile("stderr3.txt");
+       data = slurpfile(&s, "archive3");
+       assertEqualMem(data + 116, "000021 \0", 8);
+       /* Gname field in ustar header should be empty. */
+       assertEqualMem(data + 297, "\0", 1);
+
+       /* Again with just --gname */
+       failure("Error invoking %s c", testprog);
+       assertEqualInt(0,
+           systemf("%s cf archive4 --gname=foofoofoo --format=ustar file >stdout4.txt 2>stderr4.txt",
+               testprog));
+       assertEmptyFile("stdout4.txt");
+       assertEmptyFile("stderr4.txt");
+       data = slurpfile(&s, "archive4");
+       /* Gid should be unchanged from original reference. */
+       assertEqualMem(data + 116, reference + 116, 8);
+       assertEqualMem(data + 297, "foofoofoo\0", 10);
+}
diff --git a/tar/test/test_option_uid_uname.c b/tar/test/test_option_uid_uname.c
new file mode 100644 (file)
index 0000000..83ea5f1
--- /dev/null
@@ -0,0 +1,80 @@
+/*-
+ * Copyright (c) 2003-2010 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_uid_uname)
+{
+       char *reference, *data;
+       size_t s;
+
+       assertUmask(0);
+       assertMakeFile("file", 0644, "1234567890");
+
+       /* Create archive with no special options. */
+       failure("Error invoking %s c", testprog);
+       assertEqualInt(0,
+           systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt",
+               testprog));
+       assertEmptyFile("stdout1.txt");
+       assertEmptyFile("stderr1.txt");
+       reference = slurpfile(&s, "archive1");
+
+       /* Again with both --uid and --uname */
+       failure("Error invoking %s c", testprog);
+       assertEqualInt(0,
+           systemf("%s cf archive2 --uid=17 --uname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt",
+               testprog));
+       assertEmptyFile("stdout2.txt");
+       assertEmptyFile("stderr2.txt");
+       data = slurpfile(&s, "archive2");
+       /* Should force uid and uname fields in ustar header. */
+       assertEqualMem(data + 108, "000021 \0", 8);
+       assertEqualMem(data + 265, "foofoofoo\0", 10);
+
+       /* Again with just --uid */
+       failure("Error invoking %s c", testprog);
+       assertEqualInt(0,
+           systemf("%s cf archive3 --uid=17 --format=ustar file >stdout3.txt 2>stderr3.txt",
+               testprog));
+       assertEmptyFile("stdout3.txt");
+       assertEmptyFile("stderr3.txt");
+       data = slurpfile(&s, "archive3");
+       assertEqualMem(data + 108, "000021 \0", 8);
+       /* Uname field in ustar header should be empty. */
+       assertEqualMem(data + 265, "\0", 1);
+
+       /* Again with just --uname */
+       failure("Error invoking %s c", testprog);
+       assertEqualInt(0,
+           systemf("%s cf archive4 --uname=foofoofoo --format=ustar file >stdout4.txt 2>stderr4.txt",
+               testprog));
+       assertEmptyFile("stdout4.txt");
+       assertEmptyFile("stderr4.txt");
+       data = slurpfile(&s, "archive4");
+       /* Uid should be unchanged from original reference. */
+       assertEqualMem(data + 108, reference + 108, 8);
+       assertEqualMem(data + 265, "foofoofoo\0", 10);
+}
index 4f3b5df17652ca39271e3c22aba10f19f7af7e6a..359a097f5f5cf95612d688ff6efce69ad1810cae 100644 (file)
@@ -836,7 +836,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
                if (bsdtar->uid >= 0) {
                        archive_entry_set_uid(entry, bsdtar->uid);
                        if (!bsdtar->uname)
-                               archive_entry_set_gname(entry,
+                               archive_entry_set_uname(entry,
                                    archive_read_disk_uname(bsdtar->diskreader,
                                        bsdtar->uid));
                }
@@ -850,7 +850,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
                if (bsdtar->uname)
                        archive_entry_set_uname(entry, bsdtar->uname);
                if (bsdtar->gname)
-                       archive_entry_set_uname(entry, bsdtar->gname);
+                       archive_entry_set_gname(entry, bsdtar->gname);
                if (r != ARCHIVE_OK)
                        lafe_warnc(archive_errno(bsdtar->diskreader),
                            "%s", archive_error_string(bsdtar->diskreader));