]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Improve previous change; reuse a directory traversals object instead of creating...
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 28 Feb 2012 07:40:38 +0000 (16:40 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 28 Feb 2012 07:40:38 +0000 (16:40 +0900)
tar/write.c

index 3fb861277d117bef0a329a3d9816554a4adaf6da..521e2770f86208c326d08fa967294e74a2002774 100644 (file)
@@ -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));