]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix the link resolver to never match dirs as hardlinks.
authorTim Kientzle <kientzle@gmail.com>
Sat, 14 Jun 2008 21:27:26 +0000 (17:27 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sat, 14 Jun 2008 21:27:26 +0000 (17:27 -0400)
In particular, this seems to fix some recent port build failures
(the use of tar in these ports is rather bizarre, but it did work
with tar's old link-matching code).
Thanks to: Kris Kennaway

SVN-Revision: 117

libarchive/archive_entry_link_resolver.c
libarchive/test/test_link_resolver.c

index f5176a44611c0c6a746735e5236a1097bb1d0bfb..84cd60850913c917de948ad3c6938a63a5132736 100644 (file)
@@ -181,6 +181,9 @@ archive_entry_linkify(struct archive_entry_linkresolver *res,
        /* If it has only one link, then we're done. */
        if (archive_entry_nlink(*e) == 1)
                return;
+       /* Directories never have hardlinks. */
+       if (archive_entry_filetype(*e) == AE_IFDIR)
+               return;
 
        switch (res->strategy) {
        case ARCHIVE_ENTRY_LINKIFY_LIKE_TAR:
index a51e4a4ddc9fedccc7381662e10638b58c2de452..032c059510788655ff2cfbe5f525dee1b3b4fafa 100644 (file)
@@ -68,6 +68,24 @@ static void test_linkify_tar(void)
        assertEqualInt(0, archive_entry_size(entry));
 
 
+       /* Dirs should never be matched as hardlinks, regardless. */
+       archive_entry_set_pathname(entry, "test3");
+       archive_entry_set_nlink(entry, 2);
+       archive_entry_set_filetype(entry, AE_IFDIR);
+       archive_entry_set_ino(entry, 3);
+       archive_entry_set_hardlink(entry, NULL);
+       archive_entry_linkify(resolver, &entry, &e2);
+       /* Shouldn't be altered, since it wasn't seen before. */
+       assert(e2 == NULL);
+       assertEqualString("test3", archive_entry_pathname(entry));
+       assertEqualString(NULL, archive_entry_hardlink(entry));
+
+       /* Dir, so it shouldn't get matched. */
+       archive_entry_linkify(resolver, &entry, &e2);
+       assert(e2 == NULL);
+       assertEqualString("test3", archive_entry_pathname(entry));
+       assertEqualString(NULL, archive_entry_hardlink(entry));
+
        archive_entry_free(entry);
        archive_entry_linkresolver_free(resolver);
 }