From: Tim Kientzle Date: Sun, 26 Jun 2011 04:09:09 +0000 (-0400) Subject: Extend the --newer-than test to verify the behavior when there's a new X-Git-Tag: v3.0.0a~268 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff3b75e93ff3fd2156ee44e1fa7af54aa32c7fc8;p=thirdparty%2Flibarchive.git Extend the --newer-than test to verify the behavior when there's a new file inside an old directory. Rework the descent logic in write.c somewhat to fix the behavior here. SVN-Revision: 3424 --- diff --git a/tar/test/test_option_newer_than.c b/tar/test/test_option_newer_than.c index cdeed7f06..c9432dcb5 100644 --- a/tar/test/test_option_newer_than.c +++ b/tar/test/test_option_newer_than.c @@ -36,6 +36,8 @@ DEFINE_TEST(test_option_newer_than) */ assertMakeDir("test1in", 0755); assertChdir("test1in"); + assertMakeDir("a", 0755); + assertMakeDir("a/b", 0755); assertMakeFile("old.txt", 0644, "old.txt"); assertEqualInt(0, stat("old.txt", &st)); sleepUntilAfter(st.st_mtime); @@ -43,10 +45,11 @@ DEFINE_TEST(test_option_newer_than) assertEqualInt(0, stat("middle.txt", &st)); sleepUntilAfter(st.st_mtime); assertMakeFile("new.txt", 0644, "new"); + assertMakeFile("a/b/new.txt", 0644, "new file in old directory"); /* Test --newer-than on create */ - assertEqualInt(0, systemf("%s -cf ../test1.tar --newer-than middle.txt *.txt", testprog)); - assertEqualInt(0, systemf("%s -cf ../test2.tar *.txt", testprog)); + assertEqualInt(0, systemf("%s -cf ../test1.tar --newer-than middle.txt *.txt a", testprog)); + assertEqualInt(0, systemf("%s -cf ../test2.tar *.txt a", testprog)); assertChdir(".."); /* Extract test1.tar to a clean dir and verify what got archived. */ @@ -54,6 +57,7 @@ DEFINE_TEST(test_option_newer_than) assertChdir("test1out"); assertEqualInt(0, systemf("%s xf ../test1.tar", testprog)); assertFileExists("new.txt"); + assertFileExists("a/b/new.txt"); assertFileNotExists("middle.txt"); assertFileNotExists("old.txt"); assertChdir(".."); @@ -63,11 +67,9 @@ DEFINE_TEST(test_option_newer_than) assertChdir("test2out"); assertEqualInt(0, systemf("%s xf ../test2.tar --newer-than ../test1in/middle.txt", testprog)); assertFileExists("new.txt"); + assertFileExists("a/b/new.txt"); assertFileNotExists("middle.txt"); assertFileNotExists("old.txt"); assertChdir(".."); - /* TODO: old dir containing new file, should descend into dir to visit file even though we don't archive it. */ - // rm -rf t && mkdir -p t/a/b && cd t && sleep 1 && touch TIMESTAMP && sleep 1 && touch a/b/test && ../bin/bsdtar cvf /dev/null --newer-than TIMESTAMP a && cd .. - } diff --git a/tar/write.c b/tar/write.c index f13bc7857..ab3c1532c 100644 --- a/tar/write.c +++ b/tar/write.c @@ -744,6 +744,9 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path) break; } + if (bsdtar->option_no_subdirs) + descend = 0; + /* * Are we about to cross to a new filesystem? */ @@ -756,7 +759,6 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path) } else if (descend == 0) { /* We're not descending, so no need to check. */ } else if (bsdtar->option_dont_traverse_mounts) { - /* User has asked us not to cross mount points. */ descend = 0; } else { /* We're prepared to cross a mount point. */ @@ -783,8 +785,15 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path) * In -u mode, check that the file is newer than what's * already in the archive; in all modes, obey --newerXXX flags. */ - if (!new_enough(bsdtar, name, st)) + if (!new_enough(bsdtar, name, st)) { + if (!descend) + continue; + if (bsdtar->option_interactive && + !yes("add '%s'", name)) + continue; + tree_descend(tree); continue; + } archive_entry_free(entry); entry = archive_entry_new(); @@ -894,8 +903,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path) !yes("add '%s'", name)) continue; - /* Note: if user vetoes, we won't descend. */ - if (descend && !bsdtar->option_no_subdirs) + if (descend) tree_descend(tree); /*