aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/function/FileOperator.cpp
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2023-02-11 12:18:26 +0000
committerSaturneric <[email protected]>2023-02-11 12:18:26 +0000
commit8a0cbb77bb540be94737c5f85c1b7ecc8e7f6e54 (patch)
treea45727d76ab696e79718403b06663d9346796f69 /src/core/function/FileOperator.cpp
parentfreat: allow to change gnupg install path (diff)
downloadGpgFrontend-8a0cbb77bb540be94737c5f85c1b7ecc8e7f6e54.tar.gz
GpgFrontend-8a0cbb77bb540be94737c5f85c1b7ecc8e7f6e54.zip
fix: open target file once
Diffstat (limited to 'src/core/function/FileOperator.cpp')
-rw-r--r--src/core/function/FileOperator.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/core/function/FileOperator.cpp b/src/core/function/FileOperator.cpp
index 63599bd1..3732cd1a 100644
--- a/src/core/function/FileOperator.cpp
+++ b/src/core/function/FileOperator.cpp
@@ -84,30 +84,30 @@ std::string GpgFrontend::FileOperator::CalculateHash(
<< file_path.filename().u8string().c_str() << std::endl;
QFile f(info.filePath());
- f.open(QFile::ReadOnly);
- auto buffer = f.readAll();
- ss << " " << _("file size(bytes)") << _(": ") << buffer.size()
- << std::endl;
- f.close();
if (f.open(QFile::ReadOnly)) {
- auto hash_md5 = QCryptographicHash(QCryptographicHash::Md5);
+ // read all data
+ auto buffer = f.readAll();
+ ss << " " << _("file size(bytes)") << _(": ") << buffer.size()
+ << std::endl;
+
// md5
+ auto hash_md5 = QCryptographicHash(QCryptographicHash::Md5);
hash_md5.addData(buffer);
auto md5 = hash_md5.result().toHex().toStdString();
SPDLOG_INFO("md5 {}", md5);
ss << " "
<< "md5" << _(": ") << md5 << std::endl;
- auto hash_sha1 = QCryptographicHash(QCryptographicHash::Sha1);
// sha1
+ auto hash_sha1 = QCryptographicHash(QCryptographicHash::Sha1);
hash_sha1.addData(buffer);
auto sha1 = hash_sha1.result().toHex().toStdString();
SPDLOG_INFO("sha1 {}", sha1);
ss << " "
<< "sha1" << _(": ") << sha1 << std::endl;
- auto hash_sha256 = QCryptographicHash(QCryptographicHash::Sha256);
// sha1
+ auto hash_sha256 = QCryptographicHash(QCryptographicHash::Sha256);
hash_sha256.addData(buffer);
auto sha256 = hash_sha256.result().toHex().toStdString();
SPDLOG_INFO("sha256 {}", sha256);