feat: call gpgconf using the homedir option

This commit is contained in:
saturneric 2025-01-27 18:21:25 +01:00
parent bbbbbf535f
commit 22ba38aac5
2 changed files with 27 additions and 19 deletions

View File

@ -35,6 +35,7 @@
// qt // qt
#include <QCoreApplication> #include <QCoreApplication>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QJsonDocument> #include <QJsonDocument>
#include <QString> #include <QString>
@ -47,7 +48,7 @@
#include "GpgInfo.h" #include "GpgInfo.h"
GF_MODULE_API_DEFINE_V2("com.bktus.gpgfrontend.module.gnupg_info_gathering", GF_MODULE_API_DEFINE_V2("com.bktus.gpgfrontend.module.gnupg_info_gathering",
"GatherGnupgInfo", "1.2.0", "GatherGnupgInfo", "1.2.1",
"Try gathering gnupg information.", "Saturneric") "Try gathering gnupg information.", "Saturneric")
DEFINE_TRANSLATIONS_STRUCTURE(ModuleGnuPGInfoGathering); DEFINE_TRANSLATIONS_STRUCTURE(ModuleGnuPGInfoGathering);
@ -64,7 +65,8 @@ extern void GetGpgOptionInfos(void *, int, const char *, const char *);
extern auto StartGatheringAllGnuPGInfo() -> int; extern auto StartGatheringAllGnuPGInfo() -> int;
extern auto StartStartGatheringGnuPGComponentsInfo( extern auto StartStartGatheringGnuPGComponentsInfo(
const QString &gpgme_version, const QString &gpgconf_path) -> int; const QString &gpgme_version, const QString &gpgconf_path,
const QString &default_home_path) -> int;
extern auto GnupgTabFactory(void *id) -> void *; extern auto GnupgTabFactory(void *id) -> void *;
@ -95,15 +97,7 @@ auto GFActiveModule() -> int {
} }
REGISTER_EVENT_HANDLER(APPLICATION_LOADED, [](const MEvent &event) -> int { REGISTER_EVENT_HANDLER(APPLICATION_LOADED, [](const MEvent &event) -> int {
const auto gpgme_version = UDUP(GFModuleRetrieveRTValueOrDefault( // Do Nothing
DUP("core"), DUP("gpgme.version"), DUP("0.0.0")));
MLogDebug(QString("got gpgme version from rt: %1").arg(gpgme_version));
const auto gpgconf_path = UDUP(GFModuleRetrieveRTValueOrDefault(
DUP("core"), DUP("gpgme.ctx.gpgconf_path"), DUP("")));
MLogDebug(QString("got gpgconf path from rt: %1").arg(gpgconf_path));
StartStartGatheringGnuPGComponentsInfo(gpgme_version, gpgconf_path);
CB_SUCC(event); CB_SUCC(event);
}); });
@ -123,12 +117,14 @@ auto GFUnregisterModule() -> int {
} }
auto StartStartGatheringGnuPGComponentsInfo( auto StartStartGatheringGnuPGComponentsInfo(
const QString &gpgme_version, const QString &gpgconf_path) -> int { const QString &gpgme_version, const QString &gpgconf_path,
const QString &default_home_path) -> int {
auto context = Context{gpgme_version, gpgconf_path}; auto context = Context{gpgme_version, gpgconf_path};
// get all components // get all components
GFExecuteCommandSync(QDUP(gpgconf_path), 1, GFExecuteCommandSync(QDUP(gpgconf_path), 3,
QStringListToCharArray({"--list-components"}), QStringListToCharArray({"--homedir", default_home_path,
"--list-components"}),
GetGpgComponentInfos, &context); GetGpgComponentInfos, &context);
MLogDebug("loading gnupg component info done."); MLogDebug("loading gnupg component info done.");
return 0; return 0;
@ -143,13 +139,24 @@ auto StartGatheringAllGnuPGInfo() -> int {
DUP("core"), DUP("gpgme.ctx.gpgconf_path"), DUP(""))); DUP("core"), DUP("gpgme.ctx.gpgconf_path"), DUP("")));
MLogDebug(QString("got gpgconf path from rt: %1").arg(gpgconf_path)); MLogDebug(QString("got gpgconf path from rt: %1").arg(gpgconf_path));
auto default_home_path = UDUP(GFModuleRetrieveRTValueOrDefault(
DUP("core"), DUP("gpgme.ctx.default_database_path"), DUP("")));
MLogDebug(
QString("got default home path from rt: %1").arg(default_home_path));
default_home_path = QDir::toNativeSeparators(
QFileInfo(default_home_path).canonicalFilePath());
MLogDebug(QString("final default home path: %1").arg(default_home_path));
// get components infos // get components infos
StartStartGatheringGnuPGComponentsInfo(gpgme_version, gpgconf_path); StartStartGatheringGnuPGComponentsInfo(gpgme_version, gpgconf_path,
default_home_path);
QList<GFCommandExecuteContext> exec_contexts; QList<GFCommandExecuteContext> exec_contexts;
auto exec_context = GFCommandExecuteContext{ auto exec_context = GFCommandExecuteContext{
QDUP(gpgconf_path), 1, QStringListToCharArray({"--list-dirs"}), QDUP(gpgconf_path), 3,
QStringListToCharArray({"--homedir", default_home_path, "--list-dirs"}),
GetGpgDirectoryInfos, nullptr}; GetGpgDirectoryInfos, nullptr};
exec_contexts.push_back(exec_context); exec_contexts.push_back(exec_context);
@ -185,8 +192,9 @@ auto StartGatheringAllGnuPGInfo() -> int {
Context{gpgme_version, gpgconf_path, component_info}; Context{gpgme_version, gpgconf_path, component_info};
auto exec_context = GFCommandExecuteContext{ auto exec_context = GFCommandExecuteContext{
QDUP(gpgconf_path), 2, QDUP(gpgconf_path), 4,
QStringListToCharArray({"--list-options", component_info.name}), QStringListToCharArray({"--homedir", default_home_path,
"--list-options", component_info.name}),
GetGpgOptionInfos, context}; GetGpgOptionInfos, context};
exec_contexts.push_back(exec_context); exec_contexts.push_back(exec_context);
} }

View File

@ -277,7 +277,7 @@ void GnupgTab::process_software_info() {
auto option_info = option_info_json.object(); auto option_info = option_info_json.object();
if (!option_info.contains("name")) { if (!option_info.contains("name")) {
MLogWarn(QString("illegal gnupg configuation info. it doesn't have a " MLogWarn(QString("illegal gnupg configuration info. it doesn't have a "
"name, json: %1") "name, json: %1")
.arg(option_info_json_bytes)); .arg(option_info_json_bytes));
continue; continue;