}
int pakfire_keystore_init(struct pakfire* pakfire, gpgme_ctx_t* ctx) {
- char path[PATH_MAX];
+ char path[PATH_MAX] = PAKFIRE_CACHE_PATH "/tmp/pakfire-keystore.XXXXXX";
+ char* tmp = NULL;
// Initialise GPGME
int r = pakfire_init_gpgme(pakfire);
// Set output to be ASCII armoured
gpgme_set_armor(*ctx, 1);
- // Set home
- r = pakfire_make_path(pakfire, path, "/etc/pakfire/gnupg");
- if (r < 0)
+ // Create a temporary directory
+ tmp = pakfire_mkdtemp(path);
+ if (!tmp)
goto ERROR;
DEBUG(pakfire, "Using PGP database at %s\n", path);
- // Create home
- r = pakfire_mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR);
- if (r && errno != EEXIST) {
- ERROR(pakfire, "Could not initialize the PGP database at %s: %m\n", path);
- goto ERROR;
- }
-
// Setup engine
error = gpgme_ctx_set_engine_info(*ctx, GPGME_PROTOCOL_OpenPGP, NULL, path);
if (gpg_err_code(error) != GPG_ERR_NO_ERROR)
gpgme_release(*ctx);
*ctx = NULL;
+ // Cleanup temporary files
+ if (tmp)
+ pakfire_rmtree(tmp, 0);
+
return r;
}
int pakfire_keystore_destroy(struct pakfire* pakfire, gpgme_ctx_t* ctx) {
+ char path[PATH_MAX];
+
+ // Retrieve engine info
+ gpgme_engine_info_t engine_info = gpgme_ctx_get_engine_info(*ctx);
+
+ // Store a copy of the home directory
+ pakfire_string_set(path, engine_info->home_dir);
+
// Free GPGME context
gpgme_release(*ctx);
- return 0;
+ // Remove home directory
+ return pakfire_rmtree(path, 0);
}