summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar/test
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2008-11-10 05:24:13 +0000
committerkientzle <kientzle@FreeBSD.org>2008-11-10 05:24:13 +0000
commit34001f8d263157133991d55daa841af6e46068d2 (patch)
tree0033b3f8b054b5f5bbbe4622151f279d281aea4d /usr.bin/tar/test
parent19a4817b26349c90c83c0e1bee2792d456160309 (diff)
downloadFreeBSD-src-34001f8d263157133991d55daa841af6e46068d2.zip
FreeBSD-src-34001f8d263157133991d55daa841af6e46068d2.tar.gz
Include more detailed explanation of this case, since it's pretty
subtle why it comes out the way it does. Once you realize that it depends on the archiving order, it's also important to realize that filesystem differences aren't going to break this case. (Some of the other tests have had to be extensively rewritten to make them independent of the order in which a particular filesystem returns file entries.) (This commit also serves to note the PR number that I accidentally omitted from the previous commit.) PR: bin/128562 MFC after: 30 days
Diffstat (limited to 'usr.bin/tar/test')
-rw-r--r--usr.bin/tar/test/test_strip_components.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/usr.bin/tar/test/test_strip_components.c b/usr.bin/tar/test/test_strip_components.c
index 3150dfd..0cfea18 100644
--- a/usr.bin/tar/test/test_strip_components.c
+++ b/usr.bin/tar/test/test_strip_components.c
@@ -63,15 +63,44 @@ DEFINE_TEST(test_strip_components)
assertEqualInt(-1, lstat("target/d0", &st));
failure("d0/d1/ is too short and should not get restored");
assertEqualInt(-1, lstat("target/d1", &st));
- failure("d0/l1 is too short and should not get restored");
- assertEqualInt(-1, lstat("target/l1", &st));
- failure("d0/d1/l2 is a hardlink to file whose name was too short");
- assertEqualInt(-1, lstat("target/l2", &st));
- assertEqualInt(0, lstat("target/s2", &st));
failure("d0/d1/s2 is a symlink to something that won't be extracted");
assertEqualInt(-1, stat("target/s2", &st));
+ assertEqualInt(0, lstat("target/s2", &st));
failure("d0/d1/d2 should be extracted");
assertEqualInt(0, lstat("target/d2", &st));
+
+ /*
+ * 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
+ * can. Remember that tar normally stores the first file with
+ * a body and the other as hardlink entries to the first
+ * appearance. So the final result depends on the order in
+ * which these three names get archived. If d0/l1 is first,
+ * none of the three can be restored. If either of the longer
+ * names are first, then the two longer ones can both be
+ * restored.
+ *
+ * The tree-walking code used by bsdtar always visits files
+ * before subdirectories, so bsdtar's behavior is fortunately
+ * deterministic: d0/l1 will always get stored first and the
+ * other two will be stored as hardlinks to d0/l1. Since
+ * d0/l1 can't be extracted, none of these three will be
+ * extracted.
+ *
+ * It may be worth extending this test to force a particular
+ * archiving order so as to exercise both of the cases described
+ * above.
+ *
+ * Of course, this is all totally different for cpio and newc
+ * formats because the hardlink management is different.
+ * TODO: Rename this to test_strip_components_tar and create
+ * parallel tests for cpio and newc formats.
+ */
+ failure("d0/l1 is too short and should not get restored");
+ assertEqualInt(-1, lstat("target/l1", &st));
+ failure("d0/d1/l2 is a hardlink to file whose name was too short");
+ assertEqualInt(-1, lstat("target/l2", &st));
failure("d0/d1/d2/f1 is a hardlink to file whose name was too short");
assertEqualInt(-1, lstat("target/d2/f1", &st));
}
OpenPOWER on IntegriCloud