From 46f5d5eeb3b1d0586106b33cecf600ab66170b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Fri, 27 Oct 2023 16:07:16 +0200 Subject: 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 --- lang/qt/src/util.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lang/qt/src/util.h') 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 &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__ -- cgit v1.2.3