From: Joerg Sonnenberger Date: Mon, 19 May 2008 02:19:29 +0000 (-0400) Subject: Use the link resolver to detect hardlinks when writing archives X-Git-Tag: v2.6.0~224 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c8b251d06c8946c57ab627d84e2d960152fdf4a1;p=thirdparty%2Flibarchive.git Use the link resolver to detect hardlinks when writing archives using mtree files. SVN-Revision: 68 --- diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index 606e88329..e504aba62 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -77,6 +77,8 @@ struct mtree { struct archive_string current_dir; struct archive_string contents_name; + struct archive_entry_linkresolver *resolver; + off_t cur_size, cur_offset; }; @@ -145,6 +147,7 @@ cleanup(struct archive_read *a) archive_string_free(&mtree->line); archive_string_free(&mtree->current_dir); archive_string_free(&mtree->contents_name); + archive_entry_linkresolver_free(mtree->resolver); free(mtree->buff); free(mtree); (a->format->data) = NULL; @@ -278,6 +281,11 @@ read_header(struct archive_read *a, struct archive_entry *entry) } if (mtree->entries == NULL) { + mtree->resolver = archive_entry_linkresolver_new(); + if (mtree->resolver == NULL) + return ARCHIVE_FATAL; + archive_entry_linkresolver_set_strategy(mtree->resolver, + ARCHIVE_FORMAT_MTREE); r = read_mtree(a, mtree); if (r != ARCHIVE_OK) return (r); @@ -322,6 +330,7 @@ parse_file(struct archive_read *a, struct archive_entry *entry, { struct stat st; struct mtree_entry *mp; + struct archive_entry *sparse_entry; int r = ARCHIVE_OK, r1; mentry->used = 1; @@ -424,6 +433,7 @@ parse_file(struct archive_read *a, struct archive_entry *entry, archive_entry_set_dev(entry, st.st_dev); archive_entry_set_nlink(entry, st.st_nlink); } + archive_entry_linkify(mtree->resolver, &entry, &sparse_entry); } mtree->cur_size = archive_entry_size(entry); mtree->offset = 0;