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