fix: open target file once
This commit is contained in:
parent
b79ae9d7c3
commit
8a0cbb77bb
@ -84,30 +84,30 @@ std::string GpgFrontend::FileOperator::CalculateHash(
|
|||||||
<< file_path.filename().u8string().c_str() << std::endl;
|
<< file_path.filename().u8string().c_str() << std::endl;
|
||||||
|
|
||||||
QFile f(info.filePath());
|
QFile f(info.filePath());
|
||||||
f.open(QFile::ReadOnly);
|
if (f.open(QFile::ReadOnly)) {
|
||||||
|
// read all data
|
||||||
auto buffer = f.readAll();
|
auto buffer = f.readAll();
|
||||||
ss << " " << _("file size(bytes)") << _(": ") << buffer.size()
|
ss << " " << _("file size(bytes)") << _(": ") << buffer.size()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
f.close();
|
|
||||||
if (f.open(QFile::ReadOnly)) {
|
|
||||||
auto hash_md5 = QCryptographicHash(QCryptographicHash::Md5);
|
|
||||||
// md5
|
// md5
|
||||||
|
auto hash_md5 = QCryptographicHash(QCryptographicHash::Md5);
|
||||||
hash_md5.addData(buffer);
|
hash_md5.addData(buffer);
|
||||||
auto md5 = hash_md5.result().toHex().toStdString();
|
auto md5 = hash_md5.result().toHex().toStdString();
|
||||||
SPDLOG_INFO("md5 {}", md5);
|
SPDLOG_INFO("md5 {}", md5);
|
||||||
ss << " "
|
ss << " "
|
||||||
<< "md5" << _(": ") << md5 << std::endl;
|
<< "md5" << _(": ") << md5 << std::endl;
|
||||||
|
|
||||||
auto hash_sha1 = QCryptographicHash(QCryptographicHash::Sha1);
|
|
||||||
// sha1
|
// sha1
|
||||||
|
auto hash_sha1 = QCryptographicHash(QCryptographicHash::Sha1);
|
||||||
hash_sha1.addData(buffer);
|
hash_sha1.addData(buffer);
|
||||||
auto sha1 = hash_sha1.result().toHex().toStdString();
|
auto sha1 = hash_sha1.result().toHex().toStdString();
|
||||||
SPDLOG_INFO("sha1 {}", sha1);
|
SPDLOG_INFO("sha1 {}", sha1);
|
||||||
ss << " "
|
ss << " "
|
||||||
<< "sha1" << _(": ") << sha1 << std::endl;
|
<< "sha1" << _(": ") << sha1 << std::endl;
|
||||||
|
|
||||||
auto hash_sha256 = QCryptographicHash(QCryptographicHash::Sha256);
|
|
||||||
// sha1
|
// sha1
|
||||||
|
auto hash_sha256 = QCryptographicHash(QCryptographicHash::Sha256);
|
||||||
hash_sha256.addData(buffer);
|
hash_sha256.addData(buffer);
|
||||||
auto sha256 = hash_sha256.result().toHex().toStdString();
|
auto sha256 = hash_sha256.result().toHex().toStdString();
|
||||||
SPDLOG_INFO("sha256 {}", sha256);
|
SPDLOG_INFO("sha256 {}", sha256);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user