/* Initialize reasonable defaults. */
mtree->filetype = AE_IFREG;
archive_entry_set_size(entry, 0);
+ archive_string_empty(&mtree->contents_name);
/* Parse options from this line. */
parsed_kws = 0;
}
/*
- * If there is a contents file on disk, use that size;
- * otherwise leave it as-is (it might have been set from
- * the mtree size= keyword).
+ * Check for a mismatch between the type in the specification and
+ * the type of the contents object on disk.
*/
if (st != NULL) {
mismatched_type = 0;
}
}
+ /*
+ * If there is a contents file on disk, pick some of the metadata
+ * from that file. For most of these, we only set it from the contents
+ * if it wasn't already parsed from the specification.
+ */
if (st != NULL) {
if ((parsed_kws & MTREE_HAS_DEVICE) == 0 &&
(archive_entry_filetype(entry) == AE_IFCHR ||
assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
}
+/*
+ * Reported to libarchive.googlecode.com as Issue 121.
+ */
+static void
+test_read_format_mtree3(void)
+{
+ static char archive[] =
+ "#mtree\n"
+ "a type=file contents=file\n"
+ "b type=link link=a\n"
+ "c type=file contents=file\n";
+ struct archive_entry *ae;
+ struct archive *a;
+
+ assertMakeDir("mtree3", 0777);
+ assertChdir("mtree3");
+ assertMakeFile("file", 0644, "file contents");
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_support_compression_all(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_support_format_all(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_open_memory(a, archive, sizeof(archive)));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualString(archive_entry_pathname(ae), "a");
+ assertEqualInt(archive_entry_filetype(ae), AE_IFREG);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualString(archive_entry_pathname(ae), "b");
+ assertEqualInt(archive_entry_filetype(ae), AE_IFLNK);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualString(archive_entry_pathname(ae), "c");
+ assertEqualInt(archive_entry_filetype(ae), AE_IFREG);
+
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
+
+ assertChdir("..");
+}
+
DEFINE_TEST(test_read_format_mtree)
{
test_read_format_mtree1();
test_read_format_mtree2();
+ test_read_format_mtree3();
}