xref: /freebsd/contrib/libarchive/tar/test/test_option_H_upper.c (revision bd66c1b43e33540205dbc1187c2f2a15c58b57ba)
16c95142eSMartin Matuska /*-
2*bd66c1b4SMartin Matuska  * SPDX-License-Identifier: BSD-2-Clause
3*bd66c1b4SMartin Matuska  *
46c95142eSMartin Matuska  * Copyright (c) 2010 Tim Kientzle
56c95142eSMartin Matuska  * All rights reserved.
66c95142eSMartin Matuska  */
76c95142eSMartin Matuska #include "test.h"
86c95142eSMartin Matuska 
DEFINE_TEST(test_option_H_upper)96c95142eSMartin Matuska DEFINE_TEST(test_option_H_upper)
106c95142eSMartin Matuska {
116c95142eSMartin Matuska 
126c95142eSMartin Matuska 	if (!canSymlink()) {
136c95142eSMartin Matuska 		skipping("Can't test symlinks on this filesystem");
146c95142eSMartin Matuska 		return;
156c95142eSMartin Matuska 	}
166c95142eSMartin Matuska 
176c95142eSMartin Matuska 	/*
186c95142eSMartin Matuska 	 * Create a sample archive.
196c95142eSMartin Matuska 	 */
206c95142eSMartin Matuska 	assertMakeDir("in", 0755);
216c95142eSMartin Matuska 	assertChdir("in");
226c95142eSMartin Matuska 	assertMakeDir("d1", 0755);
2352c2bb75SMartin Matuska 	assertMakeSymlink("ld1", "d1", 1);
246c95142eSMartin Matuska 	assertMakeFile("d1/file1", 0644, "d1/file1");
256c95142eSMartin Matuska 	assertMakeFile("d1/file2", 0644, "d1/file2");
2652c2bb75SMartin Matuska 	assertMakeSymlink("d1/link1", "file1", 0);
2752c2bb75SMartin Matuska 	assertMakeSymlink("d1/linkX", "fileX", 0);
2852c2bb75SMartin Matuska 	assertMakeSymlink("link2", "d1/file2", 0);
2952c2bb75SMartin Matuska 	assertMakeSymlink("linkY", "d1/fileY", 0);
306c95142eSMartin Matuska 	assertChdir("..");
316c95142eSMartin Matuska 
326c95142eSMartin Matuska 	/* Test 1: Without -H */
336c95142eSMartin Matuska 	assertMakeDir("test1", 0755);
346c95142eSMartin Matuska 	assertEqualInt(0,
356c95142eSMartin Matuska 	    systemf("%s -cf test1/archive.tar -C in . >test1/c.out 2>test1/c.err", testprog));
366c95142eSMartin Matuska 	assertChdir("test1");
376c95142eSMartin Matuska 	assertEqualInt(0,
386c95142eSMartin Matuska 	    systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
3952c2bb75SMartin Matuska 	assertIsSymlink("ld1", "d1", 1);
4052c2bb75SMartin Matuska 	assertIsSymlink("d1/link1", "file1", 0);
4152c2bb75SMartin Matuska 	assertIsSymlink("d1/linkX", "fileX", 0);
4252c2bb75SMartin Matuska 	assertIsSymlink("link2", "d1/file2", 0);
4352c2bb75SMartin Matuska 	assertIsSymlink("linkY", "d1/fileY", 0);
446c95142eSMartin Matuska 	assertChdir("..");
456c95142eSMartin Matuska 
466c95142eSMartin Matuska 	/* Test 2: With -H, no symlink on command line. */
476c95142eSMartin Matuska 	assertMakeDir("test2", 0755);
486c95142eSMartin Matuska 	assertEqualInt(0,
496c95142eSMartin Matuska 	    systemf("%s -cf test2/archive.tar -H -C in . >test2/c.out 2>test2/c.err", testprog));
506c95142eSMartin Matuska 	assertChdir("test2");
516c95142eSMartin Matuska 	assertEqualInt(0,
526c95142eSMartin Matuska 	    systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
5352c2bb75SMartin Matuska 	assertIsSymlink("ld1", "d1", 1);
5452c2bb75SMartin Matuska 	assertIsSymlink("d1/link1", "file1", 0);
5552c2bb75SMartin Matuska 	assertIsSymlink("d1/linkX", "fileX", 0);
5652c2bb75SMartin Matuska 	assertIsSymlink("link2", "d1/file2", 0);
5752c2bb75SMartin Matuska 	assertIsSymlink("linkY", "d1/fileY", 0);
586c95142eSMartin Matuska 	assertChdir("..");
596c95142eSMartin Matuska 
606c95142eSMartin Matuska 	/* Test 3: With -H, some symlinks on command line. */
616c95142eSMartin Matuska 	assertMakeDir("test3", 0755);
626c95142eSMartin Matuska 	assertEqualInt(0,
63*bd66c1b4SMartin Matuska 	    systemf("%s -cf test3/archive.tar -H -C in ld1 d1 link2 linkY >test3/c.out 2>test3/c.err", testprog));
646c95142eSMartin Matuska 	assertChdir("test3");
656c95142eSMartin Matuska 	assertEqualInt(0,
666c95142eSMartin Matuska 	    systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
67f3e9b21aSMartin Matuska 	assertIsDir("ld1", umasked(0755));
6852c2bb75SMartin Matuska 	assertIsSymlink("d1/linkX", "fileX", 0);
6952c2bb75SMartin Matuska 	assertIsSymlink("d1/link1", "file1", 0);
70f3e9b21aSMartin Matuska 	assertIsReg("link2", umasked(0644));
7152c2bb75SMartin Matuska 	assertIsSymlink("linkY", "d1/fileY", 0);
726c95142eSMartin Matuska 	assertChdir("..");
73*bd66c1b4SMartin Matuska 
74*bd66c1b4SMartin Matuska #if defined(_WIN32) && !defined(__CYGWIN__)
75*bd66c1b4SMartin Matuska 	/* Test 4: With -H, using wildcards with some symlinks on command line. (wildcards are supported only in Windows) */
76*bd66c1b4SMartin Matuska 	assertMakeDir("test4", 0755);
77*bd66c1b4SMartin Matuska 	assertEqualInt(0,
78*bd66c1b4SMartin Matuska 	    systemf("%s -cf test4/archive.tar -H -C in * >test4/c.out 2>test4/c.err", testprog));
79*bd66c1b4SMartin Matuska 	assertChdir("test4");
80*bd66c1b4SMartin Matuska 	assertEqualInt(0,
81*bd66c1b4SMartin Matuska 	    systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
82*bd66c1b4SMartin Matuska 	assertIsDir("ld1", umasked(0755));
83*bd66c1b4SMartin Matuska 	assertIsSymlink("d1/linkX", "fileX", 0);
84*bd66c1b4SMartin Matuska 	assertIsSymlink("d1/link1", "file1", 0);
85*bd66c1b4SMartin Matuska 	assertIsReg("link2", umasked(0644));
86*bd66c1b4SMartin Matuska 	assertIsSymlink("linkY", "d1/fileY", 0);
87*bd66c1b4SMartin Matuska 	assertChdir("..");
88*bd66c1b4SMartin Matuska #endif
896c95142eSMartin Matuska }
90