2
* Copyright (c) 2003-2007 Tim Kientzle
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
14
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_q.c,v 1.3 2008/08/22 01:35:08 kientzle Exp $");
28
DEFINE_TEST(test_option_q)
34
* Create an archive with several different versions of the
35
* same files. By default, the last version will overwrite
36
* any earlier versions. The -q/--fast-read option will
37
* stop early, so we can verify -q/--fast-read by seeing
38
* which version of each file actually ended up being
39
* extracted. This also exercises -r mode, since that's
40
* what we use to build up the test archive.
43
f = fopen("foo", "w");
48
assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog));
50
f = fopen("foo", "w");
55
assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
57
f = fopen("bar", "w");
62
assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
64
f = fopen("foo", "w");
69
assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
71
f = fopen("bar", "w");
76
assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
79
* Now, try extracting from the test archive with various
83
/* Test 1: -q foo should only extract the first foo. */
84
assertMakeDir("test1", 0755);
86
r = systemf("%s -xf ../archive.tar -q foo >test.out 2>test.err",
88
failure("Fatal error trying to use -q option");
89
if (!assertEqualInt(0, r))
92
assertFileContents("foo1", 4, "foo");
93
assertEmptyFile("test.out");
94
assertEmptyFile("test.err");
97
/* Test 2: -q foo bar should extract up to the first bar. */
98
assertMakeDir("test2", 0755);
101
systemf("%s -xf ../archive.tar -q foo bar >test.out 2>test.err", testprog));
102
assertFileContents("foo2", 4, "foo");
103
assertFileContents("bar1", 4, "bar");
104
assertEmptyFile("test.out");
105
assertEmptyFile("test.err");
108
/* Test 3: Same as test 2, but use --fast-read spelling. */
109
assertMakeDir("test3", 0755);
110
assertChdir("test3");
112
systemf("%s -xf ../archive.tar --fast-read foo bar >test.out 2>test.err", testprog));
113
assertFileContents("foo2", 4, "foo");
114
assertFileContents("bar1", 4, "bar");
115
assertEmptyFile("test.out");
116
assertEmptyFile("test.err");
119
/* Test 4: Without -q, should extract everything. */
120
assertMakeDir("test4", 0755);
121
assertChdir("test4");
123
systemf("%s -xf ../archive.tar foo bar >test.out 2>test.err", testprog));
124
assertFileContents("foo3", 4, "foo");
125
assertFileContents("bar2", 4, "bar");
126
assertEmptyFile("test.out");
127
assertEmptyFile("test.err");