1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2010 Tim Kientzle
5 * All rights reserved.
6 */
7 #include "test.h"
8
DEFINE_TEST(test_option_H_upper)9 DEFINE_TEST(test_option_H_upper)
10 {
11
12 if (!canSymlink()) {
13 skipping("Can't test symlinks on this filesystem");
14 return;
15 }
16
17 /*
18 * Create a sample archive.
19 */
20 assertMakeDir("in", 0755);
21 assertChdir("in");
22 assertMakeDir("d1", 0755);
23 assertMakeSymlink("ld1", "d1", 1);
24 assertMakeFile("d1/file1", 0644, "d1/file1");
25 assertMakeFile("d1/file2", 0644, "d1/file2");
26 assertMakeSymlink("d1/link1", "file1", 0);
27 assertMakeSymlink("d1/linkX", "fileX", 0);
28 assertMakeSymlink("link2", "d1/file2", 0);
29 assertMakeSymlink("linkY", "d1/fileY", 0);
30 assertChdir("..");
31
32 /* Test 1: Without -H */
33 assertMakeDir("test1", 0755);
34 assertEqualInt(0,
35 systemf("%s -cf test1/archive.tar -C in . >test1/c.out 2>test1/c.err", testprog));
36 assertChdir("test1");
37 assertEqualInt(0,
38 systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
39 assertIsSymlink("ld1", "d1", 1);
40 assertIsSymlink("d1/link1", "file1", 0);
41 assertIsSymlink("d1/linkX", "fileX", 0);
42 assertIsSymlink("link2", "d1/file2", 0);
43 assertIsSymlink("linkY", "d1/fileY", 0);
44 assertChdir("..");
45
46 /* Test 2: With -H, no symlink on command line. */
47 assertMakeDir("test2", 0755);
48 assertEqualInt(0,
49 systemf("%s -cf test2/archive.tar -H -C in . >test2/c.out 2>test2/c.err", testprog));
50 assertChdir("test2");
51 assertEqualInt(0,
52 systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
53 assertIsSymlink("ld1", "d1", 1);
54 assertIsSymlink("d1/link1", "file1", 0);
55 assertIsSymlink("d1/linkX", "fileX", 0);
56 assertIsSymlink("link2", "d1/file2", 0);
57 assertIsSymlink("linkY", "d1/fileY", 0);
58 assertChdir("..");
59
60 /* Test 3: With -H, some symlinks on command line. */
61 assertMakeDir("test3", 0755);
62 assertEqualInt(0,
63 systemf("%s -cf test3/archive.tar -H -C in ld1 d1 link2 linkY >test3/c.out 2>test3/c.err", testprog));
64 assertChdir("test3");
65 assertEqualInt(0,
66 systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
67 assertIsDir("ld1", umasked(0755));
68 assertIsSymlink("d1/linkX", "fileX", 0);
69 assertIsSymlink("d1/link1", "file1", 0);
70 assertIsReg("link2", umasked(0644));
71 assertIsSymlink("linkY", "d1/fileY", 0);
72 assertChdir("..");
73
74 #if defined(_WIN32) && !defined(__CYGWIN__)
75 /* Test 4: With -H, using wildcards with some symlinks on command line. (wildcards are supported only in Windows) */
76 assertMakeDir("test4", 0755);
77 assertEqualInt(0,
78 systemf("%s -cf test4/archive.tar -H -C in * >test4/c.out 2>test4/c.err", testprog));
79 assertChdir("test4");
80 assertEqualInt(0,
81 systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
82 assertIsDir("ld1", umasked(0755));
83 assertIsSymlink("d1/linkX", "fileX", 0);
84 assertIsSymlink("d1/link1", "file1", 0);
85 assertIsReg("link2", umasked(0644));
86 assertIsSymlink("linkY", "d1/fileY", 0);
87 assertChdir("..");
88 #endif
89 }
90