aboutsummaryrefslogtreecommitdiffstats
path: root/tools/wks-util.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2018-12-04 10:37:54 +0000
committerWerner Koch <[email protected]>2018-12-05 07:41:52 +0000
commitbf29d7c822264a40f1469c7b5024d93b955a3a1e (patch)
treee3bf4e28611b502da647729b1b19f0845a0d9181 /tools/wks-util.c
parentwks: Add new commands --install-key and --remove-key to the client. (diff)
downloadgnupg-bf29d7c822264a40f1469c7b5024d93b955a3a1e.tar.gz
gnupg-bf29d7c822264a40f1469c7b5024d93b955a3a1e.zip
wks: Create sub-directories
* tools/wks-util.c (wks_compute_hu_fname): Stat and create directory if needed. Signed-off-by: Werner Koch <[email protected]> (cherry picked from commit 73e5b0ec9b9ba5e04e55f8c42d81e23df7c3afe0)
Diffstat (limited to '')
-rw-r--r--tools/wks-util.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/tools/wks-util.c b/tools/wks-util.c
index 8c9b11eb5..fe06e361f 100644
--- a/tools/wks-util.c
+++ b/tools/wks-util.c
@@ -19,6 +19,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "../common/util.h"
#include "../common/status.h"
@@ -811,6 +813,8 @@ wks_compute_hu_fname (char **r_fname, const char *addrspec)
char *hash;
const char *domain;
char sha1buf[20];
+ char *fname;
+ struct stat sb;
*r_fname = NULL;
@@ -824,12 +828,28 @@ wks_compute_hu_fname (char **r_fname, const char *addrspec)
if (!hash)
return gpg_error_from_syserror ();
- *r_fname = make_filename_try (opt.directory, domain, "hu", hash, NULL);
- if (!*r_fname)
- err = gpg_error_from_syserror ();
- else
- err = 0;
+ /* Try to create missing directories below opt.directory. */
+ fname = make_filename_try (opt.directory, domain, NULL);
+ if (fname && stat (fname, &sb)
+ && gpg_err_code_from_syserror () == GPG_ERR_ENOENT)
+ if (!gnupg_mkdir (fname, "-rwxr--r--") && opt.verbose)
+ log_info ("directory '%s' created\n", fname);
+ xfree (fname);
+ fname = make_filename_try (opt.directory, domain, "hu", NULL);
+ if (fname && stat (fname, &sb)
+ && gpg_err_code_from_syserror () == GPG_ERR_ENOENT)
+ if (!gnupg_mkdir (fname, "-rwxr--r--") && opt.verbose)
+ log_info ("directory '%s' created\n", fname);
+ xfree (fname);
+
+ /* Create the filename. */
+ fname = make_filename_try (opt.directory, domain, "hu", hash, NULL);
+ err = fname? 0 : gpg_error_from_syserror ();
+ if (err)
+ xfree (fname);
+ else
+ *r_fname = fname; /* Okay. */
xfree (hash);
return err;
}