}
assertChdir("..");
+ /*
+ * Test 1: Strip components when extracting archives.
+ */
if (canSymlink())
assertEqualInt(0, systemf("%s -cf test.tar d0/l1 d0/s1 d0/d1",
testprog));
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. */
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
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");
}