aboutsummaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/GpgCoreInit.cpp18
-rw-r--r--src/core/function/GlobalSettingStation.cpp11
-rw-r--r--src/core/utils/GpgUtils.cpp18
3 files changed, 41 insertions, 6 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index a5f86207..18fa2965 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -75,6 +75,7 @@ auto GetDefaultKeyDatabasePath(const QString& gpgconf_path) -> QString {
if (GlobalSettingStation::GetInstance().IsProtableMode()) {
default_db_path =
GlobalSettingStation::GetInstance().GetAppDataPath() + "/db";
+ LOG_D() << "default key db in protable mode:" << default_db_path;
} else {
if (gpgconf_path.isEmpty()) return {};
@@ -516,15 +517,26 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
}
auto key_dbs = GetKeyDatabaseInfoBySettings();
+ assert(!key_dbs.isEmpty());
+
+ if (key_dbs.isEmpty()) {
+ FLOG_E() << "Cannot find any valid key database!"
+ << "GpgFrontend cannot start under this situation!";
+ Module::UpsertRTValue("core", "env.state.ctx", -1);
+ CoreSignalStation::GetInstance()->SignalBadGnupgEnv(
+ QCoreApplication::tr("No valid KEy Database"));
+ }
// load default context
auto& default_ctx = GpgFrontend::GpgContext::CreateInstance(
kGpgFrontendDefaultChannel, [=]() -> ChannelObjectPtr {
GpgFrontend::GpgContextInitArgs args;
- const auto& default_key_db_info = key_dbs.front();
- args.db_name = default_key_db_info.name;
- args.db_path = default_key_db_info.path;
+ if (!key_dbs.isEmpty()) {
+ const auto& default_key_db_info = key_dbs.front();
+ args.db_name = default_key_db_info.name;
+ args.db_path = default_key_db_info.path;
+ }
args.offline_mode = forbid_all_gnupg_connection;
args.auto_import_missing_key = auto_import_missing_key;
diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp
index 62b24331..3c0dda88 100644
--- a/src/core/function/GlobalSettingStation.cpp
+++ b/src/core/function/GlobalSettingStation.cpp
@@ -48,6 +48,15 @@ class GlobalSettingStation::Impl {
Module::UpsertRTValue("core", "env.state.portable", 1);
LOG_I() << "GpgFrontend runs in the portable mode now";
+#if defined(__linux__)
+ if (!qEnvironmentVariable("APPIMAGE").isEmpty()) {
+ LOG_I() << "app image path: " << qEnvironmentVariable("APPIMAGE");
+ QFileInfo info(
+ QString::fromUtf8(qEnvironmentVariable("APPIMAGE").toUtf8()));
+ app_path_ = info.canonicalPath();
+ }
+#endif
+
app_data_path_ = QDir(app_path_ + "/../").canonicalPath();
app_config_path_ = app_data_path_ + "/config";
@@ -197,7 +206,7 @@ class GlobalSettingStation::Impl {
}
bool portable_mode_ = false;
- const QString app_path_ = QCoreApplication::applicationDirPath();
+ QString app_path_ = QCoreApplication::applicationDirPath();
QString working_path_ = QDir::currentPath();
QString app_data_path_ = QString{
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)};
diff --git a/src/core/utils/GpgUtils.cpp b/src/core/utils/GpgUtils.cpp
index ad93fe67..b8824673 100644
--- a/src/core/utils/GpgUtils.cpp
+++ b/src/core/utils/GpgUtils.cpp
@@ -289,7 +289,13 @@ auto GetCanonicalKeyDatabasePath(const QDir& app_path,
<< "to absolute path: " << target_path;
}
- auto info = QFileInfo(target_path);
+ QFileInfo info(target_path);
+ if (!info.exists()) {
+ LOG_W() << "key database not exists:" << info.canonicalFilePath()
+ << ", making a new directory...";
+ QDir().mkdir(info.canonicalFilePath());
+ }
+
if (VerifyKeyDatabasePath(info)) {
auto key_database_fs_path = info.canonicalFilePath();
LOG_D() << "load gpg key database:" << key_database_fs_path;
@@ -310,10 +316,18 @@ auto GetKeyDatabaseInfoBySettings() -> QContainer<KeyDatabaseInfo> {
// try to use user defined key database
for (const auto& key_database : key_dbs) {
+ if (key_database.path.isEmpty()) continue;
+
+ LOG_D() << "got key database:" << key_database.path;
+
auto key_database_fs_path =
GetCanonicalKeyDatabasePath(app_path, key_database.path);
- if (key_database_fs_path.isEmpty()) continue;
+ if (key_database_fs_path.isEmpty()) {
+ LOG_E() << "cannot use target path" << key_database.path
+ << "as key database";
+ continue;
+ }
KeyDatabaseInfo key_db_info;
key_db_info.name = key_database.name;