2 * Copyright (c) 2010 Tim Kientzle
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 __FBSDID("$FreeBSD$");
28 DEFINE_TEST(test_option_U_upper)
32 assertMakeFile("file1", 0644, "file1");
33 assertMakeDir("d1", 0755);
34 assertMakeFile("d1/file1", 0644, "d1/file1");
35 assertEqualInt(0, systemf("%s -cf archive.tar file1 d1/file1", testprog));
38 * bsdtar's man page used to claim that -x without -U would
39 * not break hard links. This was and is nonsense. The first
40 * two tests here simply verify that existing hard links get
44 /* Test 1: -x without -U */
45 assertMakeDir("test1", 0755);
47 assertMakeFile("file1", 0644, "file1new");
48 assertMakeHardlink("file2", "file1");
50 systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
51 assertFileContents("file1", 5, "file1");
52 assertFileContents("file1new", 8, "file2");
53 assertEmptyFile("test.out");
54 assertEmptyFile("test.err");
58 /* Test 2: -x with -U */
59 assertMakeDir("test2", 0755);
61 assertMakeFile("file1", 0644, "file1new");
62 assertMakeHardlink("file2", "file1");
64 systemf("%s -xUf ../archive.tar >test.out 2>test.err", testprog));
65 assertFileContents("file1", 5, "file1");
66 assertFileContents("file1new", 8, "file2");
67 assertEmptyFile("test.out");
68 assertEmptyFile("test.err");
72 * -U does make a difference in how bsdtar handles unwanted symlinks,
73 * though. It interacts with -P.
78 /* Test 3: Intermediate dir symlink causes error by default */
79 assertMakeDir("test3", 0755);
81 assertMakeDir("realDir", 0755);
82 assertMakeSymlink("d1", "realDir", 1);
83 r = systemf("%s -xf ../archive.tar d1/file1 >test.out 2>test.err", testprog);
85 assertIsSymlink("d1", "realDir", 1);
86 assertFileNotExists("d1/file1");
87 assertEmptyFile("test.out");
88 assertNonEmptyFile("test.err");
91 /* Test 4: Intermediate dir symlink gets removed with -U */
92 assertMakeDir("test4", 0755);
94 assertMakeDir("realDir", 0755);
95 assertMakeSymlink("d1", "realDir", 1);
97 systemf("%s -xUf ../archive.tar >test.out 2>test.err", testprog));
98 assertIsDir("d1", -1);
99 assertFileContents("d1/file1", 8, "d1/file1");
100 assertEmptyFile("test.out");
101 assertEmptyFile("test.err");
104 /* Test 5: Intermediate dir symlink is followed with -P */
105 assertMakeDir("test5", 0755);
106 assertChdir("test5");
107 assertMakeDir("realDir", 0755);
108 assertMakeSymlink("d1", "realDir", 1);
110 systemf("%s -xPf ../archive.tar d1/file1 >test.out 2>test.err", testprog));
111 assertIsSymlink("d1", "realDir", 1);
112 assertFileContents("d1/file1", 8, "d1/file1");
113 assertEmptyFile("test.out");
114 assertEmptyFile("test.err");
117 /* Test 6: Intermediate dir symlink is followed with -PU */
118 assertMakeDir("test6", 0755);
119 assertChdir("test6");
120 assertMakeDir("realDir", 0755);
121 assertMakeSymlink("d1", "realDir", 1);
123 systemf("%s -xPUf ../archive.tar d1/file1 >test.out 2>test.err", testprog));
124 assertIsSymlink("d1", "realDir", 1);
125 assertFileContents("d1/file1", 8, "d1/file1");
126 assertEmptyFile("test.out");
127 assertEmptyFile("test.err");
130 /* Test 7: Final file symlink replaced by default */
131 assertMakeDir("test7", 0755);
132 assertChdir("test7");
133 assertMakeDir("d1", 0755);
134 assertMakeFile("d1/realfile1", 0644, "realfile1");
135 assertMakeSymlink("d1/file1", "d1/realfile1", 0);
137 systemf("%s -xf ../archive.tar d1/file1 >test.out 2>test.err", testprog));
138 assertIsReg("d1/file1", umasked(0644));
139 assertFileContents("d1/file1", 8, "d1/file1");
140 assertFileContents("realfile1", 9, "d1/realfile1");
141 assertEmptyFile("test.out");
142 assertEmptyFile("test.err");
145 /* Test 8: Final file symlink replaced with -PU */
146 assertMakeDir("test8", 0755);
147 assertChdir("test8");
148 assertMakeDir("d1", 0755);
149 assertMakeFile("d1/realfile1", 0644, "realfile1");
150 assertMakeSymlink("d1/file1", "d1/realfile1", 0);
152 systemf("%s -xPUf ../archive.tar d1/file1 >test.out 2>test.err", testprog));
153 assertIsReg("d1/file1", umasked(0644));
154 assertFileContents("d1/file1", 8, "d1/file1");
155 assertFileContents("realfile1", 9, "d1/realfile1");
156 assertEmptyFile("test.out");
157 assertEmptyFile("test.err");