]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Merge r2814 from trunk: Fix Issue 121
authorTim Kientzle <kientzle@gmail.com>
Tue, 7 Dec 2010 05:06:01 +0000 (00:06 -0500)
committerTim Kientzle <kientzle@gmail.com>
Tue, 7 Dec 2010 05:06:01 +0000 (00:06 -0500)
SVN-Revision: 2817

libarchive/archive_read_support_format_mtree.c
libarchive/test/test_read_format_mtree.c

index 21d421e31a473c051ec63d6dc7695f599ac94ef5..811d1a3f93e22190a263bf1993285c95cc00b544 100644 (file)
@@ -525,6 +525,7 @@ parse_file(struct archive_read *a, struct archive_entry *entry,
        /* 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;
@@ -613,9 +614,8 @@ parse_file(struct archive_read *a, struct archive_entry *entry,
        }
 
        /*
-        * 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;
@@ -660,6 +660,11 @@ parse_file(struct archive_read *a, struct archive_entry *entry,
                }
        }
 
+       /*
+        * 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 ||
index ce6e92086dc0a0a46ad50e1799ac158b733be8ac..e6462819134dd98704f3b6038e4351286f780c64 100644 (file)
@@ -134,10 +134,53 @@ test_read_format_mtree2(void)
        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();
 }