diff options
author | Ingo Klöcker <[email protected]> | 2023-10-27 09:27:29 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2023-10-27 14:07:34 +0000 |
commit | 8d8985bda1747a18b3b1378ea7c627302a61464a (patch) | |
tree | f519130dd111c2b0c4e82224eb2a05e9c6d34500 /lang/qt/src/qgpgmesignencryptarchivejob.cpp | |
parent | Post release updates (diff) | |
download | gpgme-8d8985bda1747a18b3b1378ea7c627302a61464a.tar.gz gpgme-8d8985bda1747a18b3b1378ea7c627302a61464a.zip |
qt: Refactor removal of output file on cancel or error
* lang/qt/src/util.h, lang/qt/src/util.cpp (removeFile): New.
* lang/qt/src/qgpgmeencryptarchivejob.cpp (encrypt): Move removal of
output file from here
(encrypt_to_filename): ... to here and use new function.
* lang/qt/src/qgpgmesignarchivejob.cpp (sign): Move removal of output
file from here
(sign_to_filename): ... to here and use new function.
* lang/qt/src/qgpgmesignencryptarchivejob.cpp (sign_encrypt): Move
removal of output file from here
(sign_encrypt_to_filename): ... to here and use new function.
--
GnuPG-bug-id: 6721
Diffstat (limited to '')
-rw-r--r-- | lang/qt/src/qgpgmesignencryptarchivejob.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/lang/qt/src/qgpgmesignencryptarchivejob.cpp b/lang/qt/src/qgpgmesignencryptarchivejob.cpp index 6c28b7ec..3403ad57 100644 --- a/lang/qt/src/qgpgmesignencryptarchivejob.cpp +++ b/lang/qt/src/qgpgmesignencryptarchivejob.cpp @@ -44,6 +44,7 @@ #include "signencryptarchivejob_p.h" #include "filelistdataprovider.h" #include "qgpgme_debug.h" +#include "util.h" #include <QFile> @@ -116,20 +117,6 @@ static QGpgMESignEncryptArchiveJob::result_type sign_encrypt(Context *ctx, const auto &signingResult = res.first; const auto &encryptionResult = res.second; -#ifdef Q_OS_WIN - const auto outputFileName = QString::fromUtf8(outdata.fileName()); -#else - const auto outputFileName = QFile::decodeName(outdata.fileName()); -#endif - if (!outputFileName.isEmpty() && (signingResult.error().code() || encryptionResult.error().code())) { - // ensure that the output file is removed if the operation was canceled or failed - if (QFile::exists(outputFileName)) { - qCDebug(QGPGME_LOG) << __func__ << "Removing output file" << outputFileName << "after error or cancel"; - if (!QFile::remove(outputFileName)) { - qCDebug(QGPGME_LOG) << __func__ << "Removing output file" << outputFileName << "failed"; - } - } - } Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(signingResult, encryptionResult, log, ae); @@ -156,18 +143,26 @@ static QGpgMESignEncryptArchiveJob::result_type sign_encrypt_to_filename(Context const std::vector<GpgME::Key> &signers, const std::vector<Key> &recipients, const std::vector<QString> &paths, - const QString &outputFile, + const QString &outputFileName, Context::EncryptionFlags encryptionFlags, const QString &baseDirectory) { Data outdata; #ifdef Q_OS_WIN - outdata.setFileName(outputFile.toUtf8().constData()); + outdata.setFileName(outputFileName.toUtf8().constData()); #else - outdata.setFileName(QFile::encodeName(outputFile).constData()); + outdata.setFileName(QFile::encodeName(outputFileName).constData()); #endif - return sign_encrypt(ctx, signers, recipients, paths, outdata, encryptionFlags, baseDirectory); + const auto result = sign_encrypt(ctx, signers, recipients, paths, outdata, encryptionFlags, baseDirectory); + const auto &signingResult = std::get<0>(result); + const auto &encryptionResult = std::get<1>(result); + if (signingResult.error().code() || encryptionResult.error().code()) { + // ensure that the output file is removed if the operation was canceled or failed + removeFile(outputFileName); + } + + return result; } GpgME::Error QGpgMESignEncryptArchiveJob::start(const std::vector<GpgME::Key> &signers, |