]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Support --numeric-owner for tar extraction as well as archive creation.
authorTim Kientzle <kientzle@gmail.com>
Fri, 31 Dec 2010 17:57:48 +0000 (12:57 -0500)
committerTim Kientzle <kientzle@gmail.com>
Fri, 31 Dec 2010 17:57:48 +0000 (12:57 -0500)
This just involves reworking tar's extraction routines slightly to use
archive_read_extract2() with a custom-configured archive_write_disk
object, instead of the more convenient archive_read_extract()
interface that automatically builds a standard archive_write_disk
object.

SVN-Revision: 2849

tar/bsdtar.c
tar/bsdtar.h
tar/read.c

index 81e422b09512754b528eb5ed68a23a856e46f1a3..d42cff94ea918a14905537ea3838b1b3d417c8d3 100644 (file)
@@ -432,6 +432,7 @@ main(int argc, char **argv)
                case OPTION_NUMERIC_OWNER: /* GNU tar */
                        bsdtar->uname = "";
                        bsdtar->gname = "";
+                       bsdtar->option_numeric_owner++;
                        break;
                case 'O': /* GNU tar */
                        bsdtar->option_stdout = 1;
index 84dfc9500dbaad389ebb72f9ed96e9d8b68c140b..7803bb8f1bf3d75b6a8255b6e919888d56ffe73e 100644 (file)
@@ -72,6 +72,7 @@ struct bsdtar {
        char              option_interactive; /* -w */
        char              option_no_owner; /* -o */
        char              option_no_subdirs; /* -n */
+       char              option_numeric_owner; /* --numeric-owner */
        char              option_null; /* --null */
        char              option_stdout; /* -O */
        char              option_totals; /* --totals */
index 1e62b8e52f333aa8486b626f0c758f6e710068c6..bdf630cbceb5b7db12795e412a146defc1c25f12 100644 (file)
@@ -76,12 +76,12 @@ struct progress_data {
 
 static void    list_item_verbose(struct bsdtar *, FILE *,
                    struct archive_entry *);
-static void    read_archive(struct bsdtar *bsdtar, char mode);
+static void    read_archive(struct bsdtar *bsdtar, char mode, struct archive *);
 
 void
 tar_mode_t(struct bsdtar *bsdtar)
 {
-       read_archive(bsdtar, 't');
+       read_archive(bsdtar, 't', NULL);
        if (lafe_unmatched_inclusions_warn(bsdtar->matching, "Not found in archive") != 0)
                bsdtar->return_value = 1;
 }
@@ -89,10 +89,20 @@ tar_mode_t(struct bsdtar *bsdtar)
 void
 tar_mode_x(struct bsdtar *bsdtar)
 {
-       read_archive(bsdtar, 'x');
+       struct archive *writer;
+
+       writer = archive_write_disk_new();
+       if (writer == NULL)
+               lafe_errc(1, ENOMEM, "Cannot allocate disk writer object");
+       if (!bsdtar->option_numeric_owner)
+               archive_write_disk_set_standard_lookup(writer);
+       archive_write_disk_set_options(writer, bsdtar->extract_flags);
+
+       read_archive(bsdtar, 'x', writer);
 
        if (lafe_unmatched_inclusions_warn(bsdtar->matching, "Not found in archive") != 0)
                bsdtar->return_value = 1;
+       archive_write_free(writer);
 }
 
 static void
@@ -135,7 +145,7 @@ progress_func(void *cookie)
  * Handle 'x' and 't' modes.
  */
 static void
-read_archive(struct bsdtar *bsdtar, char mode)
+read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
 {
        struct progress_data    progress_data;
        FILE                     *out;
@@ -329,8 +339,7 @@ read_archive(struct bsdtar *bsdtar, char mode)
                        if (bsdtar->option_stdout)
                                r = archive_read_data_into_fd(a, 1);
                        else
-                               r = archive_read_extract(a, entry,
-                                   bsdtar->extract_flags);
+                               r = archive_read_extract2(a, entry, writer);
                        if (r != ARCHIVE_OK) {
                                if (!bsdtar->verbose)
                                        safe_fprintf(stderr, "%s",