Perform file hash checks asynchronously (#3815)

This commit is contained in:
Jonathan White 2019-11-09 08:02:34 -05:00 committed by Janek Bevendorff
parent 7ba9fcc0e5
commit d3978980d2

View File

@ -18,7 +18,9 @@
#include "FileWatcher.h"
#include "core/AsyncTask.h"
#include "core/Clock.h"
#include <QCryptographicHash>
#include <QFileInfo>
@ -134,17 +136,19 @@ void FileWatcher::checkFileChecksum()
QByteArray FileWatcher::calculateChecksum()
{
QFile file(m_filePath);
if (file.open(QFile::ReadOnly)) {
QCryptographicHash hash(QCryptographicHash::Sha256);
if (m_fileChecksumSizeBytes > 0) {
hash.addData(file.read(m_fileChecksumSizeBytes));
} else {
hash.addData(&file);
return AsyncTask::runAndWaitForFuture([this]() -> QByteArray {
QFile file(m_filePath);
if (file.open(QFile::ReadOnly)) {
QCryptographicHash hash(QCryptographicHash::Sha256);
if (m_fileChecksumSizeBytes > 0) {
hash.addData(file.read(m_fileChecksumSizeBytes));
} else {
hash.addData(&file);
}
return hash.result();
}
return hash.result();
}
return {};
return {};
});
}
BulkFileWatcher::BulkFileWatcher(QObject* parent)