1/*-
2 * Copyright (c) 2010 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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.
24 */
25#include "test.h"
26
27DEFINE_TEST(test_option_H_upper)
28{
29
30	if (!canSymlink()) {
31		skipping("Can't test symlinks on this filesystem");
32		return;
33	}
34
35	/*
36	 * Create a sample archive.
37	 */
38	assertMakeDir("in", 0755);
39	assertChdir("in");
40	assertMakeDir("d1", 0755);
41	assertMakeSymlink("ld1", "d1", 1);
42	assertMakeFile("d1/file1", 0644, "d1/file1");
43	assertMakeFile("d1/file2", 0644, "d1/file2");
44	assertMakeSymlink("d1/link1", "file1", 0);
45	assertMakeSymlink("d1/linkX", "fileX", 0);
46	assertMakeSymlink("link2", "d1/file2", 0);
47	assertMakeSymlink("linkY", "d1/fileY", 0);
48	assertChdir("..");
49
50	/* Test 1: Without -H */
51	assertMakeDir("test1", 0755);
52	assertEqualInt(0,
53	    systemf("%s -cf test1/archive.tar -C in . >test1/c.out 2>test1/c.err", testprog));
54	assertChdir("test1");
55	assertEqualInt(0,
56	    systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
57	assertIsSymlink("ld1", "d1", 1);
58	assertIsSymlink("d1/link1", "file1", 0);
59	assertIsSymlink("d1/linkX", "fileX", 0);
60	assertIsSymlink("link2", "d1/file2", 0);
61	assertIsSymlink("linkY", "d1/fileY", 0);
62	assertChdir("..");
63
64	/* Test 2: With -H, no symlink on command line. */
65	assertMakeDir("test2", 0755);
66	assertEqualInt(0,
67	    systemf("%s -cf test2/archive.tar -H -C in . >test2/c.out 2>test2/c.err", testprog));
68	assertChdir("test2");
69	assertEqualInt(0,
70	    systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
71	assertIsSymlink("ld1", "d1", 1);
72	assertIsSymlink("d1/link1", "file1", 0);
73	assertIsSymlink("d1/linkX", "fileX", 0);
74	assertIsSymlink("link2", "d1/file2", 0);
75	assertIsSymlink("linkY", "d1/fileY", 0);
76	assertChdir("..");
77
78	/* Test 3: With -H, some symlinks on command line. */
79	assertMakeDir("test3", 0755);
80	assertEqualInt(0,
81	    systemf("%s -cf test3/archive.tar -H -C in ld1 d1 link2 linkY >test2/c.out 2>test2/c.err", testprog));
82	assertChdir("test3");
83	assertEqualInt(0,
84	    systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
85	assertIsDir("ld1", umasked(0755));
86	assertIsSymlink("d1/linkX", "fileX", 0);
87	assertIsSymlink("d1/link1", "file1", 0);
88	assertIsReg("link2", umasked(0644));
89	assertIsSymlink("linkY", "d1/fileY", 0);
90	assertChdir("..");
91}
92