1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2003-2007 Tim Kientzle
5 * All rights reserved.
6 */
7 #include "test.h"
8
9 /* This is a little pointless, as Windows doesn't support symlinks
10 * (except for the seriously crippled CreateSymbolicLink API) so these
11 * tests won't run on Windows. */
12 #if defined(_WIN32) && !defined(__CYGWIN__)
13 #define CAT "type"
14 #define SEP "\\"
15 #else
16 #define CAT "cat"
17 #define SEP "/"
18 #endif
19
DEFINE_TEST(test_option_L_upper)20 DEFINE_TEST(test_option_L_upper)
21 {
22 FILE *filelist;
23 int r;
24
25 if (!canSymlink()) {
26 skipping("Symlink tests");
27 return;
28 }
29
30 filelist = fopen("filelist", "w");
31
32 /* Create a file and a symlink to the file. */
33 assertMakeFile("file", 0644, "1234567890");
34 fprintf(filelist, "file\n");
35
36 /* Symlink to above file. */
37 assertMakeSymlink("symlink", "file", 0);
38 fprintf(filelist, "symlink\n");
39
40 fclose(filelist);
41
42 r = systemf(CAT " filelist | %s -pd copy >copy.out 2>copy.err", testprog);
43 assertEqualInt(r, 0);
44 assertTextFileContents("1 block\n", "copy.err");
45
46 failure("Regular -p without -L should preserve symlinks.");
47 assertIsSymlink("copy/symlink", NULL, 0);
48
49 r = systemf(CAT " filelist | %s -pd -L copy-L >copy-L.out 2>copy-L.err", testprog);
50 assertEqualInt(r, 0);
51 assertEmptyFile("copy-L.out");
52 assertTextFileContents("1 block\n", "copy-L.err");
53 failure("-pdL should dereference symlinks and turn them into files.");
54 assertIsReg("copy-L/symlink", -1);
55
56 r = systemf(CAT " filelist | %s -o >archive.out 2>archive.err", testprog);
57 failure("Error invoking %s -o ", testprog);
58 assertEqualInt(r, 0);
59 assertTextFileContents("1 block\n", "archive.err");
60
61 assertMakeDir("unpack", 0755);
62 assertChdir("unpack");
63 r = systemf(CAT " .." SEP "archive.out | %s -i >unpack.out 2>unpack.err", testprog);
64
65 failure("Error invoking %s -i", testprog);
66 assertEqualInt(r, 0);
67 assertTextFileContents("1 block\n", "unpack.err");
68 assertChdir("..");
69
70 assertIsSymlink("unpack/symlink", NULL, 0);
71
72 r = systemf(CAT " filelist | %s -oL >archive-L.out 2>archive-L.err", testprog);
73 failure("Error invoking %s -oL", testprog);
74 assertEqualInt(r, 0);
75 assertTextFileContents("1 block\n", "archive-L.err");
76
77 assertMakeDir("unpack-L", 0755);
78 assertChdir("unpack-L");
79 r = systemf(CAT " .." SEP "archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog);
80
81 failure("Error invoking %s -i < archive-L.out", testprog);
82 assertEqualInt(r, 0);
83 assertTextFileContents("1 block\n", "unpack-L.err");
84 assertChdir("..");
85 assertIsReg("unpack-L/symlink", -1);
86 }
87