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 /*
10 * Verify that "cpio -p .." works.
11 */
12
DEFINE_TEST(test_passthrough_dotdot)13 DEFINE_TEST(test_passthrough_dotdot)
14 {
15 int r;
16 FILE *filelist;
17
18 assertUmask(0);
19
20 /*
21 * Create an assortment of files on disk.
22 */
23 filelist = fopen("filelist", "w");
24
25 /* Directory. */
26 assertMakeDir("dir", 0755);
27 assertChdir("dir");
28
29 fprintf(filelist, ".\n");
30
31 /* File with 10 bytes content. */
32 assertMakeFile("file", 0642, "1234567890");
33 fprintf(filelist, "file\n");
34
35 /* All done. */
36 fclose(filelist);
37
38
39 /*
40 * Use cpio passthrough mode to copy files to another directory.
41 */
42 r = systemf("%s -pdvm .. <../filelist >../stdout 2>../stderr",
43 testprog);
44 failure("Error invoking %s -pd ..", testprog);
45 assertEqualInt(r, 0);
46
47 assertChdir("..");
48
49 /* Verify stderr and stdout. */
50 assertTextFileContents("../.\n../file\n1 block\n", "stderr");
51 assertEmptyFile("stdout");
52
53 /* Regular file. */
54 assertIsReg("file", 0642);
55 assertFileSize("file", 10);
56 assertFileNLinks("file", 1);
57 }
58