]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Clear the "contents" data before parsing the next mtree entry.
authorTim Kientzle <kientzle@gmail.com>
Sun, 5 Dec 2010 23:35:40 +0000 (18:35 -0500)
committerTim Kientzle <kientzle@gmail.com>
Sun, 5 Dec 2010 23:35:40 +0000 (18:35 -0500)
This may be the cause of the problem reported in Issue 121.

SVN-Revision: 2814

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

index da7ea7055d1857a50f3d8e7541606bebff4b5011..97324116849c4bc0999b0ccaf8551ca497d9ca66 100644 (file)
@@ -528,6 +528,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;
@@ -616,9 +617,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;
@@ -663,6 +663,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 e3a3dd2815d94d62a545fcd4ab66c97cb436f9f9..1ea45ed1ed8ff7e9396f7249efc963ed7c67b151 100644 (file)
@@ -134,10 +134,53 @@ test_read_format_mtree2(void)
        assertEqualInt(ARCHIVE_OK, archive_read_free(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_free(a));
+
+       assertChdir("..");
+}
+
 
 
 DEFINE_TEST(test_read_format_mtree)
 {
        test_read_format_mtree1();
        test_read_format_mtree2();
+       test_read_format_mtree3();
 }