aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/src
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2023-08-16 12:23:15 +0000
committerIngo Klöcker <[email protected]>2023-08-16 12:23:15 +0000
commit40ca3d58963884a876c826dcf5c32673b8ddc084 (patch)
tree0bbb8ba3216464dd8fc7742d33968613ad0c5d32 /lang/qt/src
parentqt: Make toLogString helper public (diff)
downloadgpgme-40ca3d58963884a876c826dcf5c32673b8ddc084.tar.gz
gpgme-40ca3d58963884a876c826dcf5c32673b8ddc084.zip
qt: Clean up after failure or cancel of sign/encrypt archive operation
* lang/qt/src/qgpgmeencryptarchivejob.cpp (encrypt): Remove output file if operation was canceled or failed. * lang/qt/src/qgpgmesignarchivejob.cpp (sign): Ditto. * lang/qt/src/qgpgmesignencryptarchivejob.cpp (sign_encrypt): Ditto. * lang/qt/tests/run-encryptarchivejob.cpp (CommandLineOptions): Add field cancelTimeout. (parseCommandLine): Add option --cancel-after. Parse option value. (main): Check for invalid cancel timeout. Start timer for canceling the job. * lang/qt/tests/run-signarchivejob.cpp (CommandLineOptions): Add field cancelTimeout. (parseCommandLine): Add option --cancel-after. Parse option value. (main): Check for invalid cancel timeout. Start timer for canceling the job. -- This change ensures that the output file is removed if the creation of a signed or encrypted archive was canceled or failed. The new option of the test runners enables testing the cancelation of the jobs. GnuPG-bug-id: 6584
Diffstat (limited to 'lang/qt/src')
-rw-r--r--lang/qt/src/qgpgmeencryptarchivejob.cpp16
-rw-r--r--lang/qt/src/qgpgmesignarchivejob.cpp16
-rw-r--r--lang/qt/src/qgpgmesignencryptarchivejob.cpp16
3 files changed, 43 insertions, 5 deletions
diff --git a/lang/qt/src/qgpgmeencryptarchivejob.cpp b/lang/qt/src/qgpgmeencryptarchivejob.cpp
index c7f84182..ceab5909 100644
--- a/lang/qt/src/qgpgmeencryptarchivejob.cpp
+++ b/lang/qt/src/qgpgmeencryptarchivejob.cpp
@@ -43,6 +43,7 @@
#include "dataprovider.h"
#include "encryptarchivejob_p.h"
#include "filelistdataprovider.h"
+#include "qgpgme_debug.h"
#include <QFile>
@@ -101,10 +102,21 @@ static QGpgMEEncryptArchiveJob::result_type encrypt(Context *ctx,
}
flags = static_cast<Context::EncryptionFlags>(flags | Context::EncryptArchive);
- const EncryptionResult res = ctx->encrypt(recipients, indata, outdata, flags);
+ const auto encryptionResult = ctx->encrypt(recipients, indata, outdata, flags);
+
+ const auto outputFileName = QFile::decodeName(outdata.fileName());
+ if (!outputFileName.isEmpty() && 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(res, log, ae);
+ return std::make_tuple(encryptionResult, log, ae);
}
static QGpgMEEncryptArchiveJob::result_type encrypt_to_io_device(Context *ctx,
diff --git a/lang/qt/src/qgpgmesignarchivejob.cpp b/lang/qt/src/qgpgmesignarchivejob.cpp
index 005b3e44..fe87637c 100644
--- a/lang/qt/src/qgpgmesignarchivejob.cpp
+++ b/lang/qt/src/qgpgmesignarchivejob.cpp
@@ -43,6 +43,7 @@
#include "dataprovider.h"
#include "signarchivejob_p.h"
#include "filelistdataprovider.h"
+#include "qgpgme_debug.h"
#include <QFile>
@@ -108,10 +109,21 @@ static QGpgMESignArchiveJob::result_type sign(Context *ctx,
}
}
- const SigningResult res = ctx->sign(indata, outdata, GpgME::SignArchive);
+ const auto signingResult = ctx->sign(indata, outdata, GpgME::SignArchive);
+
+ const auto outputFileName = QFile::decodeName(outdata.fileName());
+ if (!outputFileName.isEmpty() && signingResult.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(res, log, ae);
+ return std::make_tuple(signingResult, log, ae);
}
static QGpgMESignArchiveJob::result_type sign_to_io_device(Context *ctx,
diff --git a/lang/qt/src/qgpgmesignencryptarchivejob.cpp b/lang/qt/src/qgpgmesignencryptarchivejob.cpp
index e47bfa0c..6670b702 100644
--- a/lang/qt/src/qgpgmesignencryptarchivejob.cpp
+++ b/lang/qt/src/qgpgmesignencryptarchivejob.cpp
@@ -43,6 +43,7 @@
#include "dataprovider.h"
#include "signencryptarchivejob_p.h"
#include "filelistdataprovider.h"
+#include "qgpgme_debug.h"
#include <QFile>
@@ -112,9 +113,22 @@ static QGpgMESignEncryptArchiveJob::result_type sign_encrypt(Context *ctx,
encryptionFlags = static_cast<Context::EncryptionFlags>(encryptionFlags | Context::EncryptArchive);
const auto res = ctx->signAndEncrypt(recipients, indata, outdata, encryptionFlags);
+ const auto &signingResult = res.first;
+ const auto &encryptionResult = res.second;
+
+ const auto outputFileName = QFile::decodeName(outdata.fileName());
+ 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(res.first, res.second, log, ae);
+ return std::make_tuple(signingResult, encryptionResult, log, ae);
}
static QGpgMESignEncryptArchiveJob::result_type sign_encrypt_to_io_device(Context *ctx,