summaryrefslogtreecommitdiff
path: root/tar/read.c
diff options
context:
space:
mode:
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>2012-10-26 15:02:24 +0900
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>2012-11-07 11:50:45 +0900
commit6f00b2a18cddba6030583ea1338465f31f83f746 (patch)
treec551166d277e96f25fd3f0e06f1fba2ea92549db /tar/read.c
parent7337f20b8c86388d92b40aa5d4dfb2e8a203e1d0 (diff)
downloadlibarchive-6f00b2a18cddba6030583ea1338465f31f83f746.tar.gz
Add support for TAR_WRITE_OPTIONS and TAR_READ_OPTIONS environmment
variables to set default options to writing or reading archives with bsdtar.
Diffstat (limited to 'tar/read.c')
-rw-r--r--tar/read.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/tar/read.c b/tar/read.c
index ba5c2e33..e2bacad9 100644
--- a/tar/read.c
+++ b/tar/read.c
@@ -155,6 +155,7 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
FILE *out;
struct archive *a;
struct archive_entry *entry;
+ const char *reader_options;
int r;
while (*bsdtar->argv) {
@@ -176,6 +177,28 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
if (cset_read_support_filter_program(bsdtar->cset, a) == 0)
archive_read_support_filter_all(a);
archive_read_support_format_all(a);
+
+ reader_options = getenv(ENV_READER_OPTIONS);
+ if (reader_options != NULL) {
+ char *p;
+ /* Set default read options. */
+ p = malloc(sizeof(IGNORE_WRONG_MODULE_NAME)
+ + strlen(reader_options) + 1);
+ if (p == NULL)
+ lafe_errc(1, errno, "Out of memory");
+ /* Prepend magic code to ignore options for
+ * a format or modules which are not added to
+ * the archive read object. */
+ strncpy(p, IGNORE_WRONG_MODULE_NAME,
+ sizeof(IGNORE_WRONG_MODULE_NAME) -1);
+ strcpy(p + sizeof(IGNORE_WRONG_MODULE_NAME) -1, reader_options);
+ r = archive_read_set_options(a, p);
+ free(p);
+ if (r == ARCHIVE_FATAL)
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+ else
+ archive_clear_error(a);
+ }
if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options))
lafe_errc(1, 0, "%s", archive_error_string(a));
if (archive_read_open_filename(a, bsdtar->filename,