diff options
author | Ingo Klöcker <[email protected]> | 2023-06-19 15:52:30 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2023-06-19 16:21:46 +0000 |
commit | e608315392cc5b7ddf51e16dce5fe7e99b83f011 (patch) | |
tree | fc455de8a1d6131d1780c2c64bc50fef6d98da48 /lang/qt/tests/run-encryptarchivejob.cpp | |
parent | core: Support writing the sign/encrypt output directly to a file (diff) | |
download | gpgme-e608315392cc5b7ddf51e16dce5fe7e99b83f011.tar.gz gpgme-e608315392cc5b7ddf51e16dce5fe7e99b83f011.zip |
qt: Support writing signed/encrypted archives directly to a file
* lang/qt/src/encryptarchivejob.cpp, lang/qt/src/encryptarchivejob.h
(EncryptArchiveJob): Add member functions setRecipients, recipients,
setInputPaths, inputPaths, setOutputFile, outputFile,
setEncryptionFlags, encryptionFlags.
* lang/qt/src/encryptarchivejob_p.h (EncryptArchiveJobPrivate): Add
members m_recipients, m_inputPaths, m_outputFilePath, m_encryptionFlags.
* lang/qt/src/qgpgmeencryptarchivejob.cpp (encrypt): Move creation of
outdata to encrypt_to_io_device.
(encrypt_to_io_device, encrypt_to_filename): New.
(QGpgMEEncryptArchiveJob::start): Use encrypt_to_io_device instead of
encrypt.
(QGpgMEEncryptArchiveJobPrivate::startIt): Start the job with the
values from member variables.
* lang/qt/src/qgpgmesignarchivejob.cpp (sign): Move creation of
outdata to sign_to_io_device.
(sign_to_io_device, sign_to_filename): New.
(QGpgMESignArchiveJob::start): Use sign_to_io_device instead of sign.
(QGpgMESignArchiveJobPrivate::startIt): Start the job with the
values from member variables.
* lang/qt/src/qgpgmesignencryptarchivejob.cpp (sign_encrypt): Move
creation of outdata to sign_encrypt_to_io_device.
(sign_encrypt_to_io_device, sign_encrypt_to_filename): New.
(QGpgMESignEncryptArchiveJob::start): Use sign_encrypt_to_io_device
instead of sign_encrypt.
(QGpgMESignEncryptArchiveJobPrivate::startIt): Start the job with the
values from member variables.
* lang/qt/src/signarchivejob.cpp, lang/qt/src/signarchivejob.h
(SignArchiveJob): Add member functions setSigner, signers,
setInputPaths, inputPaths, setOutputFile, outputFile.
* lang/qt/src/signarchivejob_p.h (SignArchiveJobPrivate): Add
members m_signers, m_inputPaths, m_outputFilePath.
* lang/qt/src/signencryptarchivejob.cpp,
lang/qt/src/signencryptarchivejob.h (SignEncryptArchiveJob): Add
member functions setSigner, signers, setRecipients, recipients,
setInputPaths, inputPaths, setOutputFile, outputFile,
setEncryptionFlags, encryptionFlags.
* lang/qt/src/signencryptarchivejob_p.h (SignEncryptArchiveJobPrivate):
Add members m_signers, m_recipients, m_inputPaths, m_outputFilePath,
m_encryptionFlags.
* lang/qt/tests/run-encryptarchivejob.cpp (createOutput): Remove.
(checkOutputFilePath): New.
(main): Create file output writing to stdout if no archive name (or "-")
is given. Exit if file with given archive name already exists. Make
the jobs write the created archive directly to the given archive name.
* lang/qt/tests/run-signarchivejob.cpp (createOutput): Remove.
(checkOutputFilePath): New.
(main): Create file output writing to stdout if no archive name (or "-")
is given. Exit if file with given archive name already exists. Make
the jobs write the created archive directly to the given archive name.
--
This makes it possible to tell gpgtar to write the created archive
directly to a specified file bypassing GpgME's Data IO.
GnuPG-bug-id: 6530
Diffstat (limited to '')
-rw-r--r-- | lang/qt/tests/run-encryptarchivejob.cpp | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/lang/qt/tests/run-encryptarchivejob.cpp b/lang/qt/tests/run-encryptarchivejob.cpp index 9ce79b6c..afbb13c0 100644 --- a/lang/qt/tests/run-encryptarchivejob.cpp +++ b/lang/qt/tests/run-encryptarchivejob.cpp @@ -41,7 +41,9 @@ #include <QCommandLineParser> #include <QCoreApplication> #include <QDebug> +#include <QDir> #include <QFile> +#include <QFileInfo> #include <context.h> #include <encryptionresult.h> @@ -95,23 +97,14 @@ CommandLineOptions parseCommandLine(const QStringList &arguments) return options; } -std::shared_ptr<QIODevice> createOutput(const QString &fileName) +QString checkOutputFilePath(const QString &fileName, const QString &baseDirectory) { - std::shared_ptr<QFile> output; - - if (fileName.isEmpty()) { - output.reset(new QFile); - output->open(stdout, QIODevice::WriteOnly); - } else { - if (QFile::exists(fileName)) { - qCritical() << "File" << fileName << "exists. Bailing out."; - } else { - output.reset(new QFile{fileName}); - output->open(QIODevice::WriteOnly); - } + const QFileInfo fi{QDir{baseDirectory}, fileName}; + if (fi.exists()) { + qCritical() << "File" << fi.filePath() << "exists. Bailing out."; + return {}; } - - return output; + return fileName; } int main(int argc, char **argv) @@ -129,9 +122,16 @@ int main(int argc, char **argv) return 1; } - auto output = createOutput(options.archiveName); - if (!output) { - return 1; + std::shared_ptr<QFile> output; + QString outputFilePath; + if (options.archiveName.isEmpty() || options.archiveName == QLatin1String{"-"}) { + output.reset(new QFile); + output->open(stdout, QIODevice::WriteOnly); + } else { + outputFilePath = checkOutputFilePath(options.archiveName, options.baseDirectory); + if (outputFilePath.isEmpty()) { + return 1; + } } if (options.sign) { @@ -148,7 +148,14 @@ int main(int argc, char **argv) qApp->quit(); }); - const auto err = job->start({}, {}, options.filesAndDirectories, output, GpgME::Context::None); + GpgME::Error err; + if (output) { + err = job->start({}, {}, options.filesAndDirectories, output, GpgME::Context::None); + } else { + job->setInputPaths(options.filesAndDirectories); + job->setOutputFile(outputFilePath); + err = job->startIt(); + } if (err) { std::cerr << "Error: Starting the job failed: " << err.asString() << std::endl; return 1; @@ -166,7 +173,14 @@ int main(int argc, char **argv) qApp->quit(); }); - const auto err = job->start({}, options.filesAndDirectories, output, GpgME::Context::None); + GpgME::Error err; + if (output) { + err = job->start({}, options.filesAndDirectories, output, GpgME::Context::None); + } else { + job->setInputPaths(options.filesAndDirectories); + job->setOutputFile(outputFilePath); + err = job->startIt(); + } if (err) { std::cerr << "Error: Starting the job failed: " << err.asString() << std::endl; return 1; |