From: Tim Kientzle Date: Fri, 31 Dec 2010 17:57:48 +0000 (-0500) Subject: Support --numeric-owner for tar extraction as well as archive creation. X-Git-Tag: v3.0.0a~797 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de7b4d67fffe31326433fa83d51680cb35e9de11;p=thirdparty%2Flibarchive.git Support --numeric-owner for tar extraction as well as archive creation. 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 --- diff --git a/tar/bsdtar.c b/tar/bsdtar.c index 81e422b09..d42cff94e 100644 --- a/tar/bsdtar.c +++ b/tar/bsdtar.c @@ -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; diff --git a/tar/bsdtar.h b/tar/bsdtar.h index 84dfc9500..7803bb8f1 100644 --- a/tar/bsdtar.h +++ b/tar/bsdtar.h @@ -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 */ diff --git a/tar/read.c b/tar/read.c index 1e62b8e52..bdf630cbc 100644 --- a/tar/read.c +++ b/tar/read.c @@ -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",