]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 160: --strip-components now works in -c mode as well as -x and -t.
authorTim Kientzle <kientzle@gmail.com>
Wed, 29 Jun 2011 04:56:26 +0000 (00:56 -0400)
committerTim Kientzle <kientzle@gmail.com>
Wed, 29 Jun 2011 04:56:26 +0000 (00:56 -0400)
SVN-Revision: 3444

tar/bsdtar.1
tar/bsdtar.c
tar/test/test_strip_components.c
tar/util.c

index 41e35ccdc3df5dfd1bddb3aa3aad0d84a1d33d5b..c71aad52c4050223ffb4394de3f3f89e07189f1c 100644 (file)
@@ -505,7 +505,6 @@ and the default behavior if
 .Nm
 is run as root.
 .It Fl Fl strip-components Ar count
-(x mode only)
 Remove the specified number of leading path elements.
 Pathnames with fewer elements will be silently skipped.
 Note that the pathname is edited after checking inclusion/exclusion patterns
index 00a13e5104cd8decc2443a16d3f4a7ce04fc6046..d69ffb3456513344b155064456faa759b2fa135a 100644 (file)
@@ -642,8 +642,6 @@ main(int argc, char **argv)
                buff[1] = bsdtar->symlink_mode;
                only_mode(bsdtar, buff, "cru");
        }
-       if (bsdtar->strip_components != 0)
-               only_mode(bsdtar, "--strip-components", "xt");
 
        /* Filename "-" implies stdio. */
        if (strcmp(bsdtar->filename, "-") == 0)
index d4a093065353edbeea4a1b61076480442e1a2eb1..d195af1b3526f4f40a246fa50601e7392f82676e 100644 (file)
@@ -41,6 +41,9 @@ DEFINE_TEST(test_strip_components)
        }
        assertChdir("..");
 
+       /*
+        * Test 1: Strip components when extracting archives.
+        */
        if (canSymlink())
                assertEqualInt(0, systemf("%s -cf test.tar d0/l1 d0/s1 d0/d1",
                    testprog));
@@ -56,6 +59,8 @@ DEFINE_TEST(test_strip_components)
        assertFileNotExists("target/d0");
        failure("d0/d1/ is too short and should not get restored");
        assertFileNotExists("target/d1");
+       failure("d0/s1 is too short and should not get restored");
+       assertFileNotExists("target/s1");
        failure("d0/d1/s2 is a symlink to something that won't be extracted");
        /* If platform supports symlinks, target/s2 is a broken symlink. */
        /* If platform does not support symlink, target/s2 doesn't exist. */
@@ -66,6 +71,8 @@ DEFINE_TEST(test_strip_components)
        assertIsDir("target/d2", -1);
 
        /*
+        * Test 1b: Strip components extracting archives involving hardlinks.
+        *
         * This next is a complicated case.  d0/l1, d0/d1/l2, and
         * d0/d1/d2/f1 are all hardlinks to the same file; d0/l1 can't
         * be extracted with --strip-components=2 and the other two
@@ -92,4 +99,41 @@ DEFINE_TEST(test_strip_components)
        assertFileNotExists("target/l2");
        failure("d0/d1/d2/f1 is a hardlink to file whose name was too short");
        assertFileNotExists("target/d2/f1");
+
+       /*
+        * Test 2: Strip components when creating archives.
+        */
+       if (canSymlink())
+               assertEqualInt(0, systemf("%s --strip-components 2 -cf test2.tar "
+                                       "d0/l1 d0/s1 d0/d1", testprog));
+       else
+               assertEqualInt(0, systemf("%s --strip-components 2 -cf test2.tar "
+                                       "d0/l1 d0/d1", testprog));
+
+       assertMakeDir("target2", 0755);
+       assertEqualInt(0, systemf("%s -x -C target2 -f test2.tar", testprog));
+
+       failure("d0/ is too short and should not have been archived");
+       assertFileNotExists("target2/d0");
+       failure("d0/d1/ is too short and should not have been archived");
+       assertFileNotExists("target2/d1");
+       failure("d0/s1 is too short and should not get restored");
+       assertFileNotExists("target/s1");
+       /* If platform supports symlinks, target/s2 is included. */
+       if (canSymlink()) {
+               failure("d0/d1/s2 is a symlink to something included in archive");
+               assertIsSymlink("target2/s2", "d2/f1");
+       }
+       failure("d0/d1/d2 should be archived");
+       assertIsDir("target2/d2", -1);
+
+       /*
+        * Test 2b: Strip components creating archives involving hardlinks.
+        */
+       failure("d0/l1 is too short and should not have been archived");
+       assertFileNotExists("target/l1");
+       failure("d0/d1/l2 is a hardlink to file whose name was too short");
+       assertFileNotExists("target/l2");
+       failure("d0/d1/d2/f1 is a hardlink to file whose name was too short");
+       assertFileNotExists("target/d2/f1");
 }
index 42e10e4517c096d02adc168a20ed3f6566bbd9f2..dbdcfd667fde2e53150f06830b57011a9396616c 100644 (file)
@@ -365,9 +365,7 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
 #if HAVE_REGEX_H
        char *subst_name;
        int r;
-#endif
 
-#if HAVE_REGEX_H
        r = apply_substitution(bsdtar, name, &subst_name, 0);
        if (r == -1) {
                lafe_warnc(0, "Invalid substitution, skipping entry");