diff options
Diffstat (limited to 'src/core/function')
-rw-r--r-- | src/core/function/gpg/GpgAdvancedOperator.cpp | 5 | ||||
-rw-r--r-- | src/core/function/gpg/GpgCommandExecutor.cpp | 26 |
2 files changed, 19 insertions, 12 deletions
diff --git a/src/core/function/gpg/GpgAdvancedOperator.cpp b/src/core/function/gpg/GpgAdvancedOperator.cpp index 4a373f0a..6b56d867 100644 --- a/src/core/function/gpg/GpgAdvancedOperator.cpp +++ b/src/core/function/gpg/GpgAdvancedOperator.cpp @@ -46,12 +46,17 @@ void GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache( return; } +#if defined(__APPLE__) && defined(__MACH__) + FLOG_I("kill all gpg components in order to clear gpg password cache"); + KillAllGpgComponents(); +#else GpgFrontend::GpgCommandExecutor::ExecuteSync( {gpgconf_path, QStringList{"--reload", "gpg-agent"}, [=](int exit_code, const QString & /*p_out*/, const QString & /*p_err*/) { cb(exit_code == 0 ? 0 : -1, TransferParams()); }}); +#endif } void GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents( diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp index 555c710d..3e218b92 100644 --- a/src/core/function/gpg/GpgCommandExecutor.cpp +++ b/src/core/function/gpg/GpgCommandExecutor.cpp @@ -139,36 +139,38 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) }; return new Thread::Task( - std::move(runner), QString("GpgCommamdExecutor(%1){%2}").arg(cmd), + std::move(runner), + QString("GpgCommamdExecutor(%1){%2}").arg(cmd).arg(arguments.join(' ')), TransferParams(cmd, arguments, interact_function, cmd_executor_callback), std::move(result_callback)); } void GpgCommandExecutor::ExecuteSync(ExecuteContext context) { Thread::Task *task = BuildTaskFromExecCtx(context); + QPointer<Thread::Task> p_t = task; - QEventLoop looper; - QObject::connect(task, &Thread::Task::SignalTaskEnd, &looper, + auto *looper = new QEventLoop(QCoreApplication::instance()); + QObject::connect(task, &Thread::Task::SignalTaskEnd, looper, &QEventLoop::quit); - Thread::TaskRunnerPtr target_task_runner = nullptr; + Thread::TaskRunnerPtr target_task_runner = context.task_runner; - if (context.task_runner != nullptr) { - target_task_runner = context.task_runner; - } else { + if (target_task_runner == nullptr) { target_task_runner = GpgFrontend::Thread::TaskRunnerGetter::GetInstance().GetTaskRunner( Thread::TaskRunnerGetter::kTaskRunnerType_External_Process); } target_task_runner->PostTask(task); - // to arvoid dead lock issue we need to check if current thread is the same as - // target thread. if it is, we can't call exec() because it will block the - // current thread. - FLOG_D("blocking until gpg command finish..."); + // to arvoid dead lock issue we need to check if current thread is the + // same as target thread. if it is, we can't call exec() because it will + // block the current thread. + FLOG_D() << "blocking until gpg command " << context.cmd << context.arguments + << " finish..."; // block until task finished // this is to keep reference vaild until task finished - looper.exec(); + looper->exec(); + looper->deleteLater(); } void GpgCommandExecutor::ExecuteConcurrentlyAsync(ExecuteContexts contexts) { |