From: Michihiro NAKAJIMA Date: Tue, 28 Feb 2012 07:40:38 +0000 (+0900) Subject: Improve previous change; reuse a directory traversals object instead of creating... X-Git-Tag: v3.0.4~2^2~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48aa2dcbefa74f692811568b17ee73bf16be323e;p=thirdparty%2Flibarchive.git Improve previous change; reuse a directory traversals object instead of creating a new one. --- diff --git a/tar/write.c b/tar/write.c index 3fb861277..521e2770f 100644 --- a/tar/write.c +++ b/tar/write.c @@ -394,7 +394,6 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) { const char *arg; struct archive_entry *entry, *sparse_entry; - struct archive *disk, *disk_saved; /* Choose a suitable copy buffer size */ bsdtar->buff_size = 64 * 1024; @@ -474,13 +473,15 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) bsdtar->argv++; } + archive_read_disk_set_matching(bsdtar->diskreader, NULL, NULL, NULL); + archive_read_disk_set_metadata_filter_callback( + bsdtar->diskreader, NULL, NULL); entry = NULL; - disk = NULL; - disk_saved = bsdtar->diskreader; archive_entry_linkify(bsdtar->resolver, &entry, &sparse_entry); while (entry != NULL) { int r; struct archive_entry *entry2; + struct archive *disk = bsdtar->diskreader; /* * This tricky code here is to correctly read the cotents @@ -488,14 +489,8 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) * is pointing at does not have any information about the * entry by this time and using archive_read_data_block() * with the disk reader consequently must fail. And we - * have to create a new disk reader object to read the - * contents. + * have to re-open the entry to read the contents. */ - if (disk == NULL && (disk = archive_read_disk_new()) == NULL) - lafe_errc(1, 0, "Cannot create read_disk object"); - else - bsdtar->diskreader = disk; - /* TODO: Work with -C option as well. */ r = archive_read_disk_open(disk, archive_entry_sourcepath(entry)); @@ -529,9 +524,6 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) entry = NULL; archive_entry_linkify(bsdtar->resolver, &entry, &sparse_entry); } - bsdtar->diskreader = disk_saved; - if (disk != NULL) - archive_read_free(disk); if (archive_write_close(a)) { lafe_warnc(0, "%s", archive_error_string(a));