diff options
author | Saturneric <[email protected]> | 2022-12-22 10:30:36 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2022-12-22 10:30:36 +0000 |
commit | 3cb623b07e50d9e95dace9966dc0337e72f57dc2 (patch) | |
tree | dfe994f28f0a6dee6151febf3b50f22adceab74e /src/core | |
parent | Merge pull request #70 from saturneric/dev/2.0.8/saturneric (diff) | |
parent | fix: continue to solve ubuntu 18.04 build issues (diff) | |
download | GpgFrontend-2.0.10.tar.gz GpgFrontend-2.0.10.zip |
fix: solve conflictsv2.0.10
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/GpgConstants.h | 4 | ||||
-rw-r--r-- | src/core/GpgContext.cpp | 13 | ||||
-rw-r--r-- | src/core/GpgCoreInit.cpp | 50 | ||||
-rw-r--r-- | src/core/GpgCoreInit.h | 12 | ||||
-rw-r--r-- | src/core/GpgFunctionObject.cpp | 8 | ||||
-rw-r--r-- | src/core/GpgFunctionObject.h | 10 | ||||
-rw-r--r-- | src/core/GpgGenKeyInfo.cpp | 111 | ||||
-rw-r--r-- | src/core/GpgGenKeyInfo.h | 12 | ||||
-rw-r--r-- | src/core/function/GlobalSettingStation.cpp | 1 | ||||
-rw-r--r-- | src/core/function/GlobalSettingStation.h | 5 | ||||
-rw-r--r-- | src/core/function/gpg/GpgKeyGetter.cpp | 5 | ||||
-rw-r--r-- | src/core/function/gpg/GpgKeyOpera.cpp | 4 | ||||
-rw-r--r-- | src/core/model/GpgKey.cpp | 7 | ||||
-rw-r--r-- | src/core/model/GpgKey.h | 4 | ||||
-rw-r--r-- | src/core/thread/TaskRunner.cpp | 9 |
15 files changed, 199 insertions, 56 deletions
diff --git a/src/core/GpgConstants.h b/src/core/GpgConstants.h index 06f8e20d..a8a87835 100644 --- a/src/core/GpgConstants.h +++ b/src/core/GpgConstants.h @@ -31,10 +31,10 @@ #include "GpgFrontendCore.h" -const int RESTART_CODE = 1000; ///< +const int RESTART_CODE = 1000; ///< only refresh ui +const int DEEP_RESTART_CODE = 1001; // refresh core and ui namespace GpgFrontend { - using ByteArray = std::string; ///< using ByteArrayPtr = std::unique_ptr<ByteArray>; ///< using StdBypeArrayPtr = std::unique_ptr<ByteArray>; ///< diff --git a/src/core/GpgContext.cpp b/src/core/GpgContext.cpp index 28857d32..7ebd9fa9 100644 --- a/src/core/GpgContext.cpp +++ b/src/core/GpgContext.cpp @@ -102,6 +102,9 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) { find_openpgp = true; info_.AppPath = engine_info->file_name; info_.GnupgVersion = engine_info->version; + info_.DatabasePath = std::string(engine_info->home_dir == nullptr + ? "default" + : engine_info->home_dir); break; case GPGME_PROTOCOL_CMS: find_cms = true; @@ -128,6 +131,16 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) { engine_info = engine_info->next; } + // set custom key db path + if (!args.db_path.empty()) { + info_.DatabasePath = args.db_path; + auto err = gpgme_ctx_set_engine_info(_ctx_ref.get(), GPGME_PROTOCOL_OpenPGP, + info_.AppPath.c_str(), + info_.DatabasePath.c_str()); + LOG(INFO) << "ctx set custom key db path:" << info_.DatabasePath; + assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR); + } + // conditional check if ((info_.GnupgVersion >= "2.0.0" && find_gpgconf && find_openpgp && find_cms) || diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index f1664b2a..9ccc693d 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -77,23 +77,69 @@ void InitLoggingSystem() { LOG(INFO) << _("log file path") << logfile_path; } +void ResetGpgFrontendCore() { reset_gpgfrontend_core(); } + void init_gpgfrontend_core() { + // read from settings file + + bool use_custom_key_database_path = false; + try { + auto& settings = + GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings(); + use_custom_key_database_path = + settings.lookup("general.use_custom_key_database_path"); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") + << _("use_custom_key_database_path"); + } + + LOG(INFO) << "core loaded if use custom key databse path: " + << use_custom_key_database_path; + + std::string custom_key_database_path; + try { + auto& settings = + GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings(); + custom_key_database_path = static_cast<std::string>( + settings.lookup("general.custom_key_database_path")); + + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") << _("custom_key_database_path"); + } + + LOG(INFO) << "core loaded custom key databse path: " + << custom_key_database_path; + // init default channel GpgFrontend::GpgContext::CreateInstance( - GPGFRONTEND_DEFAULT_CHANNEL, [&]() -> std::unique_ptr<ChannelObject> { + GPGFRONTEND_DEFAULT_CHANNEL, [=]() -> std::unique_ptr<ChannelObject> { GpgFrontend::GpgContextInitArgs args; + + // set key database path + if (use_custom_key_database_path && !custom_key_database_path.empty()) { + args.db_path = custom_key_database_path; + } + return std::unique_ptr<ChannelObject>(new GpgContext(args)); }); // init non-ascii channel GpgFrontend::GpgContext::CreateInstance( - GPGFRONTEND_NON_ASCII_CHANNEL, [&]() -> std::unique_ptr<ChannelObject> { + GPGFRONTEND_NON_ASCII_CHANNEL, [=]() -> std::unique_ptr<ChannelObject> { GpgFrontend::GpgContextInitArgs args; args.ascii = false; + + // set key database path + if (use_custom_key_database_path && !custom_key_database_path.empty()) { + args.db_path = custom_key_database_path; + } + return std::unique_ptr<ChannelObject>(new GpgContext(args)); }); } +void reset_gpgfrontend_core() { SingletonStorageCollection::GetInstance(true); } + void new_default_settings_channel(int channel) { GpgFrontend::GpgContext::CreateInstance( channel, [&]() -> std::unique_ptr<ChannelObject> { diff --git a/src/core/GpgCoreInit.h b/src/core/GpgCoreInit.h index 150e85e9..77942b56 100644 --- a/src/core/GpgCoreInit.h +++ b/src/core/GpgCoreInit.h @@ -43,11 +43,23 @@ void GPGFRONTEND_CORE_EXPORT InitLoggingSystem(); * @brief * */ +void GPGFRONTEND_CORE_EXPORT ResetGpgFrontendCore(); + +/** + * @brief + * + */ void init_gpgfrontend_core(); /** * @brief * + */ +void reset_gpgfrontend_core(); + +/** + * @brief + * * @param channel */ void new_default_settings_channel( diff --git a/src/core/GpgFunctionObject.cpp b/src/core/GpgFunctionObject.cpp index 1289d72f..6ff83d72 100644 --- a/src/core/GpgFunctionObject.cpp +++ b/src/core/GpgFunctionObject.cpp @@ -122,11 +122,15 @@ GpgFrontend::SingletonStorageCollection::GetSingletonStorage( } GpgFrontend::SingletonStorageCollection* -GpgFrontend::SingletonStorageCollection::GetInstance() { +GpgFrontend::SingletonStorageCollection::GetInstance( + bool force_refresh = false) { static SingletonStorageCollection* instance = nullptr; - if (instance == nullptr) { + + if (force_refresh || instance == nullptr) { instance = new SingletonStorageCollection(); + LOG(INFO) << "new single storage collection created: " << instance; } + return instance; } diff --git a/src/core/GpgFunctionObject.h b/src/core/GpgFunctionObject.h index de27ea42..56d0ab22 100644 --- a/src/core/GpgFunctionObject.h +++ b/src/core/GpgFunctionObject.h @@ -125,7 +125,7 @@ class GPGFRONTEND_CORE_EXPORT SingletonStorageCollection { * * @return SingletonStorageCollection* */ - static SingletonStorageCollection* GetInstance(); + static SingletonStorageCollection* GetInstance(bool force_refresh); /** * @brief Get the Singleton Storage object @@ -173,7 +173,7 @@ class SingletonFunctionObject : public ChannelObject { "T not derived from SingletonFunctionObject<T>"); auto p_storage = - SingletonStorageCollection::GetInstance()->GetSingletonStorage( + SingletonStorageCollection::GetInstance(false)->GetSingletonStorage( typeid(T)); auto* _p_pbj = (T*)(p_storage->FindObjectInChannel(channel)); @@ -200,7 +200,7 @@ class SingletonFunctionObject : public ChannelObject { "T not derived from SingletonFunctionObject<T>"); auto p_storage = - SingletonStorageCollection::GetInstance()->GetSingletonStorage( + SingletonStorageCollection::GetInstance(false)->GetSingletonStorage( typeid(T)); auto _p_pbj = (T*)(p_storage->FindObjectInChannel(channel)); @@ -219,7 +219,7 @@ class SingletonFunctionObject : public ChannelObject { * @return T& */ static void ReleaseChannel(int channel) { - SingletonStorageCollection::GetInstance() + SingletonStorageCollection::GetInstance(false) ->GetSingletonStorage(typeid(T)) ->ReleaseChannel(channel); } @@ -244,7 +244,7 @@ class SingletonFunctionObject : public ChannelObject { * @return std::vector<int> */ static std::vector<int> GetAllChannelId() { - return SingletonStorageCollection::GetInstance() + return SingletonStorageCollection::GetInstance(false) ->GetSingletonStorage(typeid(T)) ->GetAllChannelId(); } diff --git a/src/core/GpgGenKeyInfo.cpp b/src/core/GpgGenKeyInfo.cpp index 6ca83c96..f9065529 100644 --- a/src/core/GpgGenKeyInfo.cpp +++ b/src/core/GpgGenKeyInfo.cpp @@ -28,38 +28,48 @@ #include "core/GpgGenKeyInfo.h" +#include <algorithm> #include <boost/date_time/gregorian/greg_date.hpp> #include <boost/date_time/gregorian/greg_duration.hpp> #include <boost/date_time/gregorian/gregorian_types.hpp> +#include <cassert> #include <string> #include <vector> -void GpgFrontend::GenKeyInfo::SetAlgo(const std::string &m_algo) { - LOG(INFO) << "set algo" << m_algo; +void GpgFrontend::GenKeyInfo::SetAlgo( + const GpgFrontend::GenKeyInfo::KeyGenAlgo &m_algo) { + LOG(INFO) << "set algo name" << m_algo.first; // Check algo if supported - std::string algo_args = std::string(m_algo); - boost::algorithm::to_upper(algo_args); + std::string algo_args = m_algo.second; if (standalone_) { if (!subkey_) { auto support_algo = GetSupportedKeyAlgoStandalone(); - auto it = std::find(support_algo.begin(), support_algo.end(), algo_args); + auto it = std::find_if( + support_algo.begin(), support_algo.end(), + [=](const KeyGenAlgo &o) { return o.second == algo_args; }); // Algo Not Supported if (it == support_algo.end()) return; } else { auto support_algo = GetSupportedSubkeyAlgoStandalone(); - auto it = std::find(support_algo.begin(), support_algo.end(), algo_args); + auto it = std::find_if( + support_algo.begin(), support_algo.end(), + [=](const KeyGenAlgo &o) { return o.second == algo_args; }); // Algo Not Supported if (it == support_algo.end()) return; } } else { if (!subkey_) { auto support_algo = GetSupportedKeyAlgo(); - auto it = std::find(support_algo.begin(), support_algo.end(), algo_args); + auto it = std::find_if( + support_algo.begin(), support_algo.end(), + [=](const KeyGenAlgo &o) { return o.second == algo_args; }); // Algo Not Supported if (it == support_algo.end()) return; } else { auto support_algo = GetSupportedSubkeyAlgo(); - auto it = std::find(support_algo.begin(), support_algo.end(), algo_args); + auto it = std::find_if( + support_algo.begin(), support_algo.end(), + [=](const KeyGenAlgo &o) { return o.second == algo_args; }); // Algo Not Supported if (it == support_algo.end()) return; } @@ -116,22 +126,51 @@ void GpgFrontend::GenKeyInfo::SetAlgo(const std::string &m_algo) { suggest_max_key_size_ = -1; suggest_size_addition_step_ = -1; SetKeyLength(-1); - } else if (algo_args == "elg") { - /** - * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths - * ranging from 1024 to 4096 bits. - */ + } else if (algo_args == "cv25519") { SetAllowAuthentication(false); allow_change_authentication_ = false; SetAllowSigning(false); allow_change_signing_ = false; + SetAllowCertification(false); + allow_change_certification_ = false; + suggest_min_key_size_ = 1024; suggest_max_key_size_ = 4096; suggest_size_addition_step_ = 1024; SetKeyLength(2048); + } else if (algo_args == "nistp256" || algo_args == "nistp384" || + algo_args == "nistp521") { + SetAllowAuthentication(false); + allow_change_authentication_ = false; + + SetAllowSigning(false); + allow_change_signing_ = false; + + SetAllowCertification(false); + allow_change_certification_ = false; + + suggest_min_key_size_ = -1; + suggest_max_key_size_ = -1; + suggest_size_addition_step_ = -1; + SetKeyLength(-1); + } else if (algo_args == "brainpoolp256r1") { + SetAllowAuthentication(false); + allow_change_authentication_ = false; + + SetAllowSigning(false); + allow_change_signing_ = false; + + SetAllowCertification(false); + allow_change_certification_ = false; + + suggest_min_key_size_ = -1; + suggest_max_key_size_ = -1; + suggest_size_addition_step_ = -1; + SetKeyLength(-1); } + this->algo_ = algo_args; } @@ -194,32 +233,52 @@ void GpgFrontend::GenKeyInfo::SetAllowCertification( GpgFrontend::GenKeyInfo::GenKeyInfo(bool m_is_sub_key, bool m_standalone) : standalone_(m_standalone), subkey_(m_is_sub_key) { - SetAlgo("rsa"); + assert(GetSupportedKeyAlgo().size() > 0); + SetAlgo(GetSupportedKeyAlgo()[0]); } -const std::vector<std::string> &GpgFrontend::GenKeyInfo::GetSupportedKeyAlgo() { - static const std::vector<std::string> support_key_algo = {"RSA", "DSA", - "ED25519"}; +const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo> + &GpgFrontend::GenKeyInfo::GetSupportedKeyAlgo() { + static const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo> + support_key_algo = { + {"RSA", "RSA"}, + {"DSA", "DSA"}, + {"ECDSA", "ED25519"}, + }; return support_key_algo; } -const std::vector<std::string> +const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo> &GpgFrontend::GenKeyInfo::GetSupportedSubkeyAlgo() { - static const std::vector<std::string> support_subkey_algo = {"RSA", "DSA", - "ED25519"}; + static const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo> + support_subkey_algo = { + {"RSA", "RSA"}, + {"DSA", "DSA"}, + {"ECDSA", "ED25519"}, + {"ECDH NIST P-256", "NISTP256"}, + {"ECDH NIST P-384", "NISTP384"}, + {"ECDH NIST P-521", "NISTP521"}, + // {"ECDH BrainPool P-256", "BRAINPOOlP256R1"} + }; return support_subkey_algo; } -const std::vector<std::string> +const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo> &GpgFrontend::GenKeyInfo::GetSupportedKeyAlgoStandalone() { - static const std::vector<std::string> support_subkey_algo_standalone = { - "RSA", "DSA"}; + static const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo> + support_subkey_algo_standalone = { + {"RSA", "RSA"}, + {"DSA", "DSA"}, + }; return support_subkey_algo_standalone; } -const std::vector<std::string> +const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo> &GpgFrontend::GenKeyInfo::GetSupportedSubkeyAlgoStandalone() { - static const std::vector<std::string> support_subkey_algo_standalone = { - "RSA", "DSA", "ELG-E"}; + static const std::vector<GpgFrontend::GenKeyInfo::KeyGenAlgo> + support_subkey_algo_standalone = { + {"RSA", "RSA"}, + {"DSA", "DSA"}, + }; return support_subkey_algo_standalone; } diff --git a/src/core/GpgGenKeyInfo.h b/src/core/GpgGenKeyInfo.h index 73dd9680..d47b803e 100644 --- a/src/core/GpgGenKeyInfo.h +++ b/src/core/GpgGenKeyInfo.h @@ -62,34 +62,36 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { std::string passphrase_; ///< + using KeyGenAlgo = std::pair<std::string, std::string>; + public: /** * @brief Get the Supported Key Algo object * * @return const std::vector<std::string>& */ - static const std::vector<std::string> &GetSupportedKeyAlgo(); + static const std::vector<KeyGenAlgo> &GetSupportedKeyAlgo(); /** * @brief Get the Supported Subkey Algo object * * @return const std::vector<std::string>& */ - static const std::vector<std::string> &GetSupportedSubkeyAlgo(); + static const std::vector<KeyGenAlgo> &GetSupportedSubkeyAlgo(); /** * @brief Get the Supported Key Algo Standalone object * * @return const std::vector<std::string>& */ - static const std::vector<std::string> &GetSupportedKeyAlgoStandalone(); + static const std::vector<KeyGenAlgo> &GetSupportedKeyAlgoStandalone(); /** * @brief Get the Supported Subkey Algo Standalone object * * @return const std::vector<std::string>& */ - static const std::vector<std::string> &GetSupportedSubkeyAlgoStandalone(); + static const std::vector<KeyGenAlgo> &GetSupportedSubkeyAlgoStandalone(); /** * @brief @@ -171,7 +173,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { * * @param m_algo */ - void SetAlgo(const std::string &m_algo); + void SetAlgo(const GpgFrontend::GenKeyInfo::KeyGenAlgo &m_algo); /** * @brief Get the Key Size Str object diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index db8d1bc3..7231ac9e 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -55,6 +55,7 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept LOG(INFO) << _("App Data Path") << app_data_path_; LOG(INFO) << _("App Log Path") << app_log_path_; LOG(INFO) << _("App Locale Path") << app_locale_path_; + LOG(INFO) << _("App Conf Path") << ui_config_path_; if (!is_directory(app_configure_path_)) create_directory(app_configure_path_); diff --git a/src/core/function/GlobalSettingStation.h b/src/core/function/GlobalSettingStation.h index 58282466..8811623f 100644 --- a/src/core/function/GlobalSettingStation.h +++ b/src/core/function/GlobalSettingStation.h @@ -173,10 +173,9 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) .toStdString(); ///< Program Configure Location std::filesystem::path ui_config_dir_path_ = - app_configure_path_ / - "UserInterface"; ///< Configure File Directory Location + app_configure_path_ / "conf"; ///< Configure File Directory Location std::filesystem::path ui_config_path_ = - ui_config_dir_path_ / "ui.cfg"; ///< UI Configure File Location + ui_config_dir_path_ / "main.cfg"; ///< Main Configure File Location libconfig::Config ui_cfg_; ///< UI Configure File diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp index ff848e0e..571e8797 100644 --- a/src/core/function/gpg/GpgKeyGetter.cpp +++ b/src/core/function/gpg/GpgKeyGetter.cpp @@ -88,13 +88,10 @@ GpgFrontend::KeyLinkListPtr GpgFrontend::GpgKeyGetter::FetchKey() { auto keys_list = std::make_unique<GpgKeyLinkList>(); - LOG(INFO) << "cache address:" << &keys_cache_ << "object address" << this; - for (const auto& [key, value] : keys_cache_) { LOG(INFO) << "FetchKey Id:" << value.GetId(); keys_list->push_back(value.Copy()); } - LOG(INFO) << "ended"; return keys_list; } @@ -141,8 +138,6 @@ void GpgFrontend::GpgKeyGetter::FlushKeyCache() { err = gpgme_op_keylist_end(ctx_); assert(check_gpg_error_2_err_code(err, GPG_ERR_EOF) == GPG_ERR_NO_ERROR); - - LOG(INFO) << "ended"; } GpgFrontend::KeyListPtr GpgFrontend::GpgKeyGetter::GetKeys( diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp index 03d8c8d9..0839c132 100644 --- a/src/core/function/gpg/GpgKeyOpera.cpp +++ b/src/core/function/gpg/GpgKeyOpera.cpp @@ -245,6 +245,10 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateSubkey( const GpgKey& key, const std::unique_ptr<GenKeyInfo>& params) { if (!params->IsSubKey()) return GPG_ERR_CANCELED; + LOG(INFO) << "generate subkey" + << "algo" << params->GetAlgo() << "key size" + << params->GetKeySizeStr(); + auto algo_utf8 = (params->GetAlgo() + params->GetKeySizeStr()); const char* algo = algo_utf8.c_str(); unsigned long expires = 0; diff --git a/src/core/model/GpgKey.cpp b/src/core/model/GpgKey.cpp index ad88a649..4716d9cc 100644 --- a/src/core/model/GpgKey.cpp +++ b/src/core/model/GpgKey.cpp @@ -28,6 +28,8 @@ #include "core/model/GpgKey.h" +#include <mutex> + GpgFrontend::GpgKey::GpgKey(gpgme_key_t &&key) : key_ref_(std::move(key)) {} GpgFrontend::GpgKey::GpgKey(GpgKey &&k) noexcept { swap(key_ref_, k.key_ref_); } @@ -225,7 +227,10 @@ bool GpgFrontend::GpgKey::IsHasActualEncryptionCapability() const { } GpgFrontend::GpgKey GpgFrontend::GpgKey::Copy() const { - gpgme_key_ref(key_ref_.get()); + { + const std::lock_guard<std::mutex> guard(gpgme_key_opera_mutex); + gpgme_key_ref(key_ref_.get()); + } auto *_new_key_ref = key_ref_.get(); return GpgKey(std::move(_new_key_ref)); } diff --git a/src/core/model/GpgKey.h b/src/core/model/GpgKey.h index 4761f8a5..8c24ca5d 100644 --- a/src/core/model/GpgKey.h +++ b/src/core/model/GpgKey.h @@ -29,6 +29,8 @@ #ifndef GPGFRONTEND_GPGKEY_H #define GPGFRONTEND_GPGKEY_H +#include <mutex> + #include "GpgSubKey.h" #include "GpgUID.h" @@ -353,6 +355,8 @@ class GPGFRONTEND_CORE_EXPORT GpgKey { std::unique_ptr<struct _gpgme_key, _key_ref_deleter>; ///< KeyRefHandler key_ref_ = nullptr; ///< + + mutable std::mutex gpgme_key_opera_mutex; // mutex for gpgme key operations }; } // namespace GpgFrontend diff --git a/src/core/thread/TaskRunner.cpp b/src/core/thread/TaskRunner.cpp index 7116ca71..f70b2d4c 100644 --- a/src/core/thread/TaskRunner.cpp +++ b/src/core/thread/TaskRunner.cpp @@ -36,19 +36,18 @@ GpgFrontend::Thread::TaskRunner::TaskRunner() = default; GpgFrontend::Thread::TaskRunner::~TaskRunner() = default; void GpgFrontend::Thread::TaskRunner::PostTask(Task* task) { - LOG(TRACE) << "Post Task" << task->GetUUID(); + std::string uuid = task->GetUUID(); + LOG(TRACE) << "Post Task" << uuid; if (task == nullptr) return; task->setParent(nullptr); task->moveToThread(this); - connect(task, &Task::SignalTaskPostFinishedDone, this, [=]() { - auto it = pending_tasks_.find(task->GetUUID()); + connect(task, &Task::SignalTaskPostFinishedDone, this, [&, uuid]() { + auto it = pending_tasks_.find(uuid); if (it == pending_tasks_.end()) { - LOG(ERROR) << "Task" << task->GetUUID() << "not found in pending tasks"; return; } else { - LOG(TRACE) << "Task" << task->GetUUID() << "found in pending tasks"; it->second->deleteLater(); pending_tasks_.erase(it); } |