aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/tests/run-encryptarchivejob.cpp
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/tests/run-encryptarchivejob.cpp
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 '')
-rw-r--r--lang/qt/tests/run-encryptarchivejob.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/lang/qt/tests/run-encryptarchivejob.cpp b/lang/qt/tests/run-encryptarchivejob.cpp
index afbb13c0..c1d617fb 100644
--- a/lang/qt/tests/run-encryptarchivejob.cpp
+++ b/lang/qt/tests/run-encryptarchivejob.cpp
@@ -44,6 +44,7 @@
#include <QDir>
#include <QFile>
#include <QFileInfo>
+#include <QTimer>
#include <context.h>
#include <encryptionresult.h>
@@ -63,6 +64,7 @@ struct CommandLineOptions {
bool sign = false;
QString archiveName;
QString baseDirectory;
+ std::chrono::seconds cancelTimeout{0};
std::vector<QString> filesAndDirectories;
};
@@ -78,6 +80,7 @@ CommandLineOptions parseCommandLine(const QStringList &arguments)
{{"o", "output"}, "Write output to FILE.", "FILE"},
{{"a", "armor"}, "Create ASCII armored output."},
{{"C", "directory"}, "Change to DIRECTORY before creating the archive.", "DIRECTORY"},
+ {"cancel-after", "Cancel the running job after SECONDS seconds.", "SECONDS"},
});
parser.addPositionalArgument("files", "Files and directories to add to the archive", "[files] [directories]");
@@ -92,6 +95,13 @@ CommandLineOptions parseCommandLine(const QStringList &arguments)
options.sign = parser.isSet("sign");
options.archiveName = parser.value("output");
options.baseDirectory = parser.value("directory");
+ if (parser.isSet("cancel-after")) {
+ bool ok;
+ options.cancelTimeout = std::chrono::seconds{parser.value("cancel-after").toInt(&ok)};
+ if (!ok) {
+ options.cancelTimeout = std::chrono::seconds{-1};
+ }
+ }
std::copy(args.begin(), args.end(), std::back_inserter(options.filesAndDirectories));
return options;
@@ -115,6 +125,9 @@ int main(int argc, char **argv)
app.setApplicationName("run-encryptarchivejob");
const auto options = parseCommandLine(app.arguments());
+ if (options.cancelTimeout.count() < 0) {
+ std::cerr << "Ignoring invalid timeout for cancel." << std::endl;
+ }
if ((options.sign && !QGpgME::SignEncryptArchiveJob::isSupported())
|| (!options.sign && !QGpgME::EncryptArchiveJob::isSupported())) {
@@ -147,6 +160,12 @@ int main(int argc, char **argv)
std::cerr << "Encryption Result: " << encryptionResult << std::endl;
qApp->quit();
});
+ if (options.cancelTimeout.count() > 0) {
+ QTimer::singleShot(options.cancelTimeout, job, [job]() {
+ std::cerr << "Canceling job" << std::endl;
+ job->slotCancel();
+ });
+ }
GpgME::Error err;
if (output) {
@@ -172,6 +191,12 @@ int main(int argc, char **argv)
std::cerr << "Result: " << result << std::endl;
qApp->quit();
});
+ if (options.cancelTimeout.count() > 0) {
+ QTimer::singleShot(options.cancelTimeout, job, [job]() {
+ std::cerr << "Canceling job" << std::endl;
+ job->slotCancel();
+ });
+ }
GpgME::Error err;
if (output) {