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