From 419adf41afa40e5b34f646f2cb16d8aebda20048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 23 Jan 2023 12:17:22 +0100 Subject: core: Allow setting the base directory when creating an archive * src/engine-gpg.c (gpg_encrypt, gpg_encrypt_sign, gpg_sign): Pass file name set in data with --directory option to gpgtar. * tests/run-encrypt.c (show_usage): New option --directory. (main): Parse new option. Set file name of input data to option value. * tests/run-sign.c (show_usage): New option --directory. (main): Parse new option. Set file name of input data to option value. -- GnuPG-bug-id: 6342 --- tests/run-encrypt.c | 16 ++++++++++++++++ tests/run-sign.c | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/run-encrypt.c b/tests/run-encrypt.c index 82a2cead..2d1c6e9d 100644 --- a/tests/run-encrypt.c +++ b/tests/run-encrypt.c @@ -134,6 +134,7 @@ show_usage (int ex) " --wrap assume input is valid OpenPGP message\n" " --symmetric encrypt symmetric (OpenPGP only)\n" " --archive encrypt given file or directory into an archive\n" + " --directory DIR switch to directory DIR before encrypting into an archive\n" " --diagnostics print diagnostics\n" , stderr); exit (ex); @@ -157,6 +158,7 @@ main (int argc, char **argv) gpgme_key_t keys[10+1]; int keycount = 0; char *keystring = NULL; + const char *directory = NULL; int i; gpgme_encrypt_flags_t flags = GPGME_ENCRYPT_ALWAYS_TRUST; gpgme_off_t offset; @@ -266,6 +268,14 @@ main (int argc, char **argv) flags |= GPGME_ENCRYPT_ARCHIVE; argc--; argv++; } + else if (!strcmp (*argv, "--directory")) + { + argc--; argv++; + if (!argc) + show_usage (1); + directory = *argv; + argc--; argv++; + } else if (!strcmp (*argv, "--diagnostics")) { diagnostics = 1; @@ -319,6 +329,12 @@ main (int argc, char **argv) { const char *path = *argv; err = gpgme_data_new_from_mem (&in, path, strlen (path), 0); + fail_if_err (err); + if (directory) + { + err = gpgme_data_set_file_name (in, directory); + fail_if_err (err); + } } else { diff --git a/tests/run-sign.c b/tests/run-sign.c index 73a970d0..84d7c070 100644 --- a/tests/run-sign.c +++ b/tests/run-sign.c @@ -88,6 +88,7 @@ show_usage (int ex) " --include-key-block use this option with gpg\n" " --clear create a clear text signature\n" " --archive create a signed archive with the given file or directory\n" + " --directory DIR switch to directory DIR before creating the archive\n" " --diagnostics print diagnostics\n" , stderr); exit (ex); @@ -101,6 +102,7 @@ main (int argc, char **argv) gpgme_error_t err; gpgme_ctx_t ctx; const char *key_string = NULL; + const char *directory = NULL; gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP; gpgme_sig_mode_t sigmode = GPGME_SIG_MODE_NORMAL; gpgme_data_t in, out; @@ -186,6 +188,14 @@ main (int argc, char **argv) sigmode = GPGME_SIG_MODE_ARCHIVE; argc--; argv++; } + else if (!strcmp (*argv, "--directory")) + { + argc--; argv++; + if (!argc) + show_usage (1); + directory = *argv; + argc--; argv++; + } else if (!strcmp (*argv, "--diagnostics")) { diagnostics = 1; @@ -253,6 +263,12 @@ main (int argc, char **argv) { const char *path = *argv; err = gpgme_data_new_from_mem (&in, path, strlen (path), 0); + fail_if_err (err); + if (directory) + { + err = gpgme_data_set_file_name (in, directory); + fail_if_err (err); + } } else { -- cgit v1.2.3