summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2018-12-04 11:37:54 +0100
committerWerner Koch <wk@gnupg.org>2018-12-04 15:31:41 +0100
commit73e5b0ec9b9ba5e04e55f8c42d81e23df7c3afe0 (patch)
treea82fbf580d84c04f9e64ae0ea81d0ed5a9fcfe71 /tools
parentwks: Add new commands --install-key and --remove-key to the client. (diff)
downloadgnupg2-73e5b0ec9b9ba5e04e55f8c42d81e23df7c3afe0.tar.xz
gnupg2-73e5b0ec9b9ba5e04e55f8c42d81e23df7c3afe0.zip
wks: Create sub-directories
* tools/wks-util.c (wks_compute_hu_fname): Stat and create directory if needed. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'tools')
-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 604194376..c0ea06a29 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;
}