diff options
author | Ingo Klöcker <[email protected]> | 2023-10-27 14:07:16 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2023-10-27 14:07:34 +0000 |
commit | 46f5d5eeb3b1d0586106b33cecf600ab66170b45 (patch) | |
tree | 58b4e222157b0770eb0603174906f55fba5bf525 /lang/qt/src/util.h | |
parent | qt: Refactor removal of output file on cancel or error (diff) | |
download | gpgme-46f5d5eeb3b1d0586106b33cecf600ab66170b45.tar.gz gpgme-46f5d5eeb3b1d0586106b33cecf600ab66170b45.zip |
qt: Use temporary .part file names when creating archives
* lang/qt/src/util.h, lang/qt/src/util.cpp (class PartialFileGuard):
New.
* lang/qt/src/util.cpp (getRandomCharacters, createPartFileName): New.
* lang/qt/src/qgpgmeencryptarchivejob.cpp (encrypt_to_filename): Use
PartialFileGuard.
* lang/qt/src/qgpgmesignarchivejob.cpp (sign_to_filename): Ditto.
* lang/qt/src/qgpgmesignencryptarchivejob.cpp
(sign_encrypt_to_filename): Ditto.
--
When creating signed and/or encrypted archives, gpgtar now writes the
result to a temporary file name. On success, the archive is renamed to
the final file name. Otherwise, the (partially written) temporary file
is removed (if possible).
GnuPG-bug-id: 6721
Diffstat (limited to 'lang/qt/src/util.h')
-rw-r--r-- | lang/qt/src/util.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lang/qt/src/util.h b/lang/qt/src/util.h index 9128e4bf..c2d63405 100644 --- a/lang/qt/src/util.h +++ b/lang/qt/src/util.h @@ -57,4 +57,26 @@ QStringList toFingerprints(const std::vector<GpgME::Key> &keys); void removeFile(const QString &fileName); +/** + * Helper for using a temporary "part" file for writing a result to, similar + * to what browsers do when downloading files. + * On success, you commit() which renames the temporary file to the + * final file name. Otherwise, you do nothing and let the helper remove the + * temporary file on destruction. + */ +class PartialFileGuard +{ +public: + explicit PartialFileGuard(const QString &fileName); + ~PartialFileGuard(); + + QString tempFileName() const; + + bool commit(); + +private: + QString mFileName; + QString mTempFileName; +}; + #endif // __QGPGME_UTIL_H__ |