1*543adbedSBen Gras /*-
2*543adbedSBen Gras * Copyright (c) 2003-2007 Tim Kientzle
3*543adbedSBen Gras * All rights reserved.
4*543adbedSBen Gras *
5*543adbedSBen Gras * Redistribution and use in source and binary forms, with or without
6*543adbedSBen Gras * modification, are permitted provided that the following conditions
7*543adbedSBen Gras * are met:
8*543adbedSBen Gras * 1. Redistributions of source code must retain the above copyright
9*543adbedSBen Gras * notice, this list of conditions and the following disclaimer.
10*543adbedSBen Gras * 2. Redistributions in binary form must reproduce the above copyright
11*543adbedSBen Gras * notice, this list of conditions and the following disclaimer in the
12*543adbedSBen Gras * documentation and/or other materials provided with the distribution.
13*543adbedSBen Gras *
14*543adbedSBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15*543adbedSBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16*543adbedSBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17*543adbedSBen Gras * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18*543adbedSBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19*543adbedSBen Gras * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*543adbedSBen Gras * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21*543adbedSBen Gras * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*543adbedSBen Gras * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23*543adbedSBen Gras * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*543adbedSBen Gras */
25*543adbedSBen Gras #include "test.h"
26*543adbedSBen Gras __FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_passthrough_reverse.c,v 1.2 2008/08/24 06:21:00 kientzle Exp $");
27*543adbedSBen Gras
28*543adbedSBen Gras /*
29*543adbedSBen Gras * As reported by Bernd Walter: Some people are in the habit of
30*543adbedSBen Gras * using "find -d" to generate a list for cpio -p because that
31*543adbedSBen Gras * copies the top-level dir last, which preserves owner and mode
32*543adbedSBen Gras * information. That's not necessary for bsdcpio (libarchive defers
33*543adbedSBen Gras * restoring directory information), but bsdcpio should still generate
34*543adbedSBen Gras * the correct results with this usage.
35*543adbedSBen Gras */
36*543adbedSBen Gras
DEFINE_TEST(test_passthrough_reverse)37*543adbedSBen Gras DEFINE_TEST(test_passthrough_reverse)
38*543adbedSBen Gras {
39*543adbedSBen Gras int r;
40*543adbedSBen Gras FILE *filelist;
41*543adbedSBen Gras
42*543adbedSBen Gras assertUmask(0);
43*543adbedSBen Gras
44*543adbedSBen Gras /*
45*543adbedSBen Gras * Create an assortment of files on disk.
46*543adbedSBen Gras */
47*543adbedSBen Gras filelist = fopen("filelist", "w");
48*543adbedSBen Gras
49*543adbedSBen Gras /* Directory. */
50*543adbedSBen Gras assertMakeDir("dir", 0743);
51*543adbedSBen Gras
52*543adbedSBen Gras /* File with 10 bytes content. */
53*543adbedSBen Gras assertMakeFile("dir/file", 0644, "1234567890");
54*543adbedSBen Gras fprintf(filelist, "dir/file\n");
55*543adbedSBen Gras
56*543adbedSBen Gras /* Write dir last. */
57*543adbedSBen Gras fprintf(filelist, "dir\n");
58*543adbedSBen Gras
59*543adbedSBen Gras /* All done. */
60*543adbedSBen Gras fclose(filelist);
61*543adbedSBen Gras
62*543adbedSBen Gras
63*543adbedSBen Gras /*
64*543adbedSBen Gras * Use cpio passthrough mode to copy files to another directory.
65*543adbedSBen Gras */
66*543adbedSBen Gras r = systemf("%s -pdvm out <filelist >stdout 2>stderr", testprog);
67*543adbedSBen Gras failure("Error invoking %s -pd out", testprog);
68*543adbedSBen Gras assertEqualInt(r, 0);
69*543adbedSBen Gras
70*543adbedSBen Gras assertChdir("out");
71*543adbedSBen Gras
72*543adbedSBen Gras /* Verify stderr and stdout. */
73*543adbedSBen Gras assertTextFileContents("out/dir/file\nout/dir\n1 block\n",
74*543adbedSBen Gras "../stderr");
75*543adbedSBen Gras assertEmptyFile("../stdout");
76*543adbedSBen Gras
77*543adbedSBen Gras /* dir */
78*543adbedSBen Gras assertIsDir("dir", 0743);
79*543adbedSBen Gras
80*543adbedSBen Gras
81*543adbedSBen Gras /* Regular file. */
82*543adbedSBen Gras assertIsReg("dir/file", 0644);
83*543adbedSBen Gras assertFileSize("dir/file", 10);
84*543adbedSBen Gras assertFileNLinks("dir/file", 1);
85*543adbedSBen Gras }
86