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 * As reported by Bernd Walter: Some people are in the habit of
11 * using "find -d" to generate a list for cpio -p because that
12 * copies the top-level dir last, which preserves owner and mode
13 * information. That's not necessary for bsdcpio (libarchive defers
14 * restoring directory information), but bsdcpio should still generate
15 * the correct results with this usage.
16 */
17
DEFINE_TEST(test_passthrough_reverse)18 DEFINE_TEST(test_passthrough_reverse)
19 {
20 int r;
21 FILE *filelist;
22
23 assertUmask(0);
24
25 /*
26 * Create an assortment of files on disk.
27 */
28 filelist = fopen("filelist", "w");
29
30 /* Directory. */
31 assertMakeDir("dir", 0743);
32
33 /* File with 10 bytes content. */
34 assertMakeFile("dir/file", 0644, "1234567890");
35 fprintf(filelist, "dir/file\n");
36
37 /* Write dir last. */
38 fprintf(filelist, "dir\n");
39
40 /* All done. */
41 fclose(filelist);
42
43
44 /*
45 * Use cpio passthrough mode to copy files to another directory.
46 */
47 r = systemf("%s -pdvm out <filelist >stdout 2>stderr", testprog);
48 failure("Error invoking %s -pd out", testprog);
49 assertEqualInt(r, 0);
50
51 assertChdir("out");
52
53 /* Verify stderr and stdout. */
54 assertTextFileContents("out/dir/file\nout/dir\n1 block\n",
55 "../stderr");
56 assertEmptyFile("../stdout");
57
58 /* dir */
59 assertIsDir("dir", 0743);
60
61
62 /* Regular file. */
63 assertIsReg("dir/file", 0644);
64 assertFileSize("dir/file", 10);
65 assertFileNLinks("dir/file", 1);
66 }
67