Skip to content

Commit

Permalink
Issue 327: tar should accept zero-sized exclude files with -X
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kientzle committed Jan 10, 2015
1 parent 610567e commit f93e32f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libarchive/archive_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions tar/test/test_option_X_upper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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("..");
}

0 comments on commit f93e32f

Please sign in to comment.