2 * Copyright (c) 2010 Tim Kientzle
3 * Copyright (c) 2012 Michihiro NAKAJIMA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 __FBSDID("$FreeBSD$");
29 DEFINE_TEST(test_option_older_than)
34 * Basic test of --older-than.
35 * First, create three files with different mtimes.
36 * Create test1.tar with --older-than, test2.tar without.
38 assertMakeDir("test1in", 0755);
39 assertChdir("test1in");
40 assertMakeDir("a", 0755);
41 assertMakeDir("a/b", 0755);
42 assertMakeFile("old.txt", 0644, "old.txt");
43 assertMakeFile("a/b/old.txt", 0644, "old file in old directory");
44 assertEqualInt(0, stat("old.txt", &st));
45 sleepUntilAfter(st.st_mtime);
46 assertMakeFile("middle.txt", 0644, "middle.txt");
47 assertEqualInt(0, stat("middle.txt", &st));
48 sleepUntilAfter(st.st_mtime);
49 assertMakeFile("new.txt", 0644, "new");
50 assertMakeFile("a/b/new.txt", 0644, "new file in old directory");
52 /* Test --older-than on create */
54 systemf("%s --format pax -cf ../test1.tar "
55 "--older-than middle.txt *.txt a",
58 systemf("%s --format pax -cf ../test2.tar *.txt a",
62 /* Extract test1.tar to a clean dir and verify what got archived. */
63 assertMakeDir("test1out", 0755);
64 assertChdir("test1out");
65 assertEqualInt(0, systemf("%s xf ../test1.tar", testprog));
66 assertFileNotExists("new.txt");
67 assertFileNotExists("a/b/new.txt");
68 assertFileNotExists("middle.txt");
69 assertFileExists("old.txt");
70 assertFileExists("a/b/old.txt");
73 /* Extract test2.tar to a clean dir with --older-than and verify. */
74 assertMakeDir("test2out", 0755);
75 assertChdir("test2out");
77 systemf("%s xf ../test2.tar --older-than ../test1in/middle.txt",
79 assertFileNotExists("new.txt");
80 assertFileNotExists("a/b/new.txt");
81 assertFileNotExists("middle.txt");
82 assertFileExists("old.txt");
83 assertFileExists("a/b/old.txt");