]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 327: tar should accept zero-sized exclude files with -X
authorTim Kientzle <kientzle@acm.org>
Sat, 10 Jan 2015 18:27:11 +0000 (10:27 -0800)
committerTim Kientzle <kientzle@acm.org>
Sat, 10 Jan 2015 18:27:11 +0000 (10:27 -0800)
Key problem:  We were using archive_read_format_raw() to read
the exclude file which does not accept empty files.
Enabling archive_read_format_empty() and reworking the
end-of-input handling fixed this.

Also add a test for this case to prevent it from regressing.

libarchive/archive_match.c
tar/test/test_option_X_upper.c

index 6fb86445cd295825b0668455f38d62d0029e0660..74aaacb5a22913dcf12b7d6c06200e9fed542e3b 100644 (file)
@@ -580,6 +580,7 @@ add_pattern_from_file(struct archive_match *a, struct match_list *mlist,
                return (ARCHIVE_FATAL);
        }
        r = archive_read_support_format_raw(ar);
+       r = archive_read_support_format_empty(ar);
        if (r != ARCHIVE_OK) {
                archive_copy_error(&(a->archive), ar);
                archive_read_free(ar);
@@ -596,9 +597,13 @@ add_pattern_from_file(struct archive_match *a, struct match_list *mlist,
        }
        r = archive_read_next_header(ar, &ae);
        if (r != ARCHIVE_OK) {
-               archive_copy_error(&(a->archive), ar);
                archive_read_free(ar);
-               return (r);
+               if (r == ARCHIVE_EOF) {
+                       return (ARCHIVE_OK);
+               } else {
+                       archive_copy_error(&(a->archive), ar);
+                       return (r);
+               }
        }
 
        archive_string_init(&as);
index 1aa21fc90a670f319151849a90eb32675d6322f0..4916af2970e81f65841a955fd157fbd850fc2fb3 100644 (file)
@@ -142,4 +142,18 @@ DEFINE_TEST(test_option_X_upper)
        assertEmptyFile("test.out");
        assertEmptyFile("test.err");
        assertChdir("..");
+
+       /* Test 8: with empty exclusions file */
+       assertMakeDir("test8", 0755);
+       assertChdir("test8");
+       assertMakeFile("exclusions", 0644, "");
+       assertEqualInt(0,
+           systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog));
+       assertFileContents("file1", 5, "file1");
+       assertFileContents("file2", 5, "file2");
+       assertFileContents("file3a", 6, "file3a");
+       assertFileContents("file4a", 6, "file4a");
+       assertEmptyFile("test.out");
+       assertEmptyFile("test.err");
+       assertChdir("..");
 }