From 3bec97e1b2a0c9dd9dad1a019ffe838c0a11fe0d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 29 Nov 2017 18:15:22 +0100 Subject: [PATCH] key: Ensure that GPG database directory exists Signed-off-by: Michael Tremer --- src/libpakfire/key.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libpakfire/key.c b/src/libpakfire/key.c index f38b6332e..819b8d2c7 100644 --- a/src/libpakfire/key.c +++ b/src/libpakfire/key.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include @@ -50,6 +52,19 @@ gpgme_ctx_t pakfire_get_gpgctx(Pakfire pakfire) { // Use GPG const char* path = pakfire_get_path(pakfire); char* home = pakfire_path_join(path, "etc/pakfire/gnupg"); + + // Check if gpg directories exist + if (pakfire_access(home, NULL, R_OK) != 0) { + DEBUG("Creating GPG database at %s\n", home); + + int r = pakfire_mkdir(home, S_IRUSR|S_IWUSR|S_IXUSR); + if (r) { + ERROR("Could not initialize the GPG database at %s\n", home); + return NULL; + } + } + + // Setup engine error = gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, NULL, home); pakfire_free(home); if (gpg_err_code(error) != GPG_ERR_NO_ERROR) -- 2.39.5