mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
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>
This commit is contained in:
parent
602b190963
commit
73e5b0ec9b
@ -19,6 +19,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "../common/util.h"
|
#include "../common/util.h"
|
||||||
#include "../common/status.h"
|
#include "../common/status.h"
|
||||||
@ -811,6 +813,8 @@ wks_compute_hu_fname (char **r_fname, const char *addrspec)
|
|||||||
char *hash;
|
char *hash;
|
||||||
const char *domain;
|
const char *domain;
|
||||||
char sha1buf[20];
|
char sha1buf[20];
|
||||||
|
char *fname;
|
||||||
|
struct stat sb;
|
||||||
|
|
||||||
*r_fname = NULL;
|
*r_fname = NULL;
|
||||||
|
|
||||||
@ -824,12 +828,28 @@ wks_compute_hu_fname (char **r_fname, const char *addrspec)
|
|||||||
if (!hash)
|
if (!hash)
|
||||||
return gpg_error_from_syserror ();
|
return gpg_error_from_syserror ();
|
||||||
|
|
||||||
*r_fname = make_filename_try (opt.directory, domain, "hu", hash, NULL);
|
/* Try to create missing directories below opt.directory. */
|
||||||
if (!*r_fname)
|
fname = make_filename_try (opt.directory, domain, NULL);
|
||||||
err = gpg_error_from_syserror ();
|
if (fname && stat (fname, &sb)
|
||||||
else
|
&& gpg_err_code_from_syserror () == GPG_ERR_ENOENT)
|
||||||
err = 0;
|
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);
|
xfree (hash);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user