1 /*- 2 * Copyright (c) 2010 Tim Kientzle 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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. 24 */ 25 #include "test.h" 26 27 DEFINE_TEST(test_option_newer_than) 28 { 29 struct stat st; 30 31 /* 32 * Basic test of --newer-than. 33 * First, create three files with different mtimes. 34 * Create test1.tar with --newer-than, test2.tar without. 35 */ 36 assertMakeDir("test1in", 0755); 37 assertChdir("test1in"); 38 assertMakeDir("a", 0755); 39 assertMakeDir("a/b", 0755); 40 assertMakeFile("old.txt", 0644, "old.txt"); 41 assertEqualInt(0, stat("old.txt", &st)); 42 sleepUntilAfter(st.st_mtime); 43 assertMakeFile("middle.txt", 0644, "middle.txt"); 44 assertEqualInt(0, stat("middle.txt", &st)); 45 sleepUntilAfter(st.st_mtime); 46 assertMakeFile("new.txt", 0644, "new"); 47 assertMakeFile("a/b/new.txt", 0644, "new file in old directory"); 48 49 /* Test --newer-than on create */ 50 assertEqualInt(0, 51 systemf("%s --format pax -cf ../test1.tar " 52 "--newer-than middle.txt *.txt a", testprog)); 53 assertEqualInt(0, 54 systemf("%s --format pax -cf ../test2.tar *.txt a", testprog)); 55 assertChdir(".."); 56 57 /* Extract test1.tar to a clean dir and verify what got archived. */ 58 assertMakeDir("test1out", 0755); 59 assertChdir("test1out"); 60 assertEqualInt(0, systemf("%s xf ../test1.tar", testprog)); 61 assertFileExists("new.txt"); 62 assertFileExists("a/b/new.txt"); 63 assertFileNotExists("middle.txt"); 64 assertFileNotExists("old.txt"); 65 assertChdir(".."); 66 67 /* Extract test2.tar to a clean dir with --newer-than and verify. */ 68 assertMakeDir("test2out", 0755); 69 assertChdir("test2out"); 70 assertEqualInt(0, systemf("%s xf ../test2.tar --newer-than ../test1in/middle.txt", testprog)); 71 assertFileExists("new.txt"); 72 assertFileExists("a/b/new.txt"); 73 assertFileNotExists("middle.txt"); 74 assertFileNotExists("old.txt"); 75 assertChdir(".."); 76 77 } 78