]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Extend the --newer-than test to verify the behavior when there's a new
authorTim Kientzle <kientzle@gmail.com>
Sun, 26 Jun 2011 04:09:09 +0000 (00:09 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sun, 26 Jun 2011 04:09:09 +0000 (00:09 -0400)
file inside an old directory.  Rework the descent logic in write.c
somewhat to fix the behavior here.

SVN-Revision: 3424

tar/test/test_option_newer_than.c
tar/write.c

index cdeed7f062252314aeb28c2c4a6fe38fd5f9a203..c9432dcb5f75823501cd9b6616438634feaacbde 100644 (file)
@@ -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 ..
-
 }
index f13bc7857b5433403b47d7a371f5e695b79d75ef..ab3c1532c0e5f61fa43cd0a97c233830bf59ab66 100644 (file)
@@ -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);
 
                /*