From 127aba9a4d6c1aabb4a18a74b16d3bddc6eb5c54 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 25 Nov 2015 18:29:22 +0100 Subject: tools/gpgtar: Handle '--directory' argument. * tools/gpgtar-extract.c (gpgtar_extract): Only generate a directory name if none is given via arguments. * tools/gpgtar.c (enum cmd_and_opt_values): New constant. (opts): Add argument. (main): Parse argument. * tools/gpgtar.h (opt): New field 'directory'. Signed-off-by: Justus Winter --- tools/gpgtar-extract.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'tools/gpgtar-extract.c') diff --git a/tools/gpgtar-extract.c b/tools/gpgtar-extract.c index 92346b0e0..fa2f3626a 100644 --- a/tools/gpgtar-extract.c +++ b/tools/gpgtar-extract.c @@ -312,31 +312,36 @@ gpgtar_extract (const char *filename, int decrypt) goto leave; } - if (filename) - { - dirprefix = strrchr (filename, '/'); - if (dirprefix) - dirprefix++; - else - dirprefix = filename; - } - else if (opt.filename) + if (opt.directory) + dirname = xtrystrdup (opt.directory); + else { - dirprefix = strrchr (opt.filename, '/'); - if (dirprefix) - dirprefix++; - else - dirprefix = opt.filename; - } + if (filename) + { + dirprefix = strrchr (filename, '/'); + if (dirprefix) + dirprefix++; + else + dirprefix = filename; + } + else if (opt.filename) + { + dirprefix = strrchr (opt.filename, '/'); + if (dirprefix) + dirprefix++; + else + dirprefix = opt.filename; + } - if (!dirprefix || !*dirprefix) - dirprefix = "GPGARCH"; + if (!dirprefix || !*dirprefix) + dirprefix = "GPGARCH"; - dirname = create_directory (dirprefix); - if (!dirname) - { - err = gpg_error (GPG_ERR_GENERAL); - goto leave; + dirname = create_directory (dirprefix); + if (!dirname) + { + err = gpg_error (GPG_ERR_GENERAL); + goto leave; + } } if (opt.verbose) -- cgit v1.2.3