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 "FileWatcher.h"
#include "core/AsyncTask.h"
#include "core/Clock.h" #include "core/Clock.h"
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QFileInfo> #include <QFileInfo>
@ -134,6 +136,7 @@ void FileWatcher::checkFileChecksum()
QByteArray FileWatcher::calculateChecksum() QByteArray FileWatcher::calculateChecksum()
{ {
return AsyncTask::runAndWaitForFuture([this]() -> QByteArray {
QFile file(m_filePath); QFile file(m_filePath);
if (file.open(QFile::ReadOnly)) { if (file.open(QFile::ReadOnly)) {
QCryptographicHash hash(QCryptographicHash::Sha256); QCryptographicHash hash(QCryptographicHash::Sha256);
@ -145,6 +148,7 @@ QByteArray FileWatcher::calculateChecksum()
return hash.result(); return hash.result();
} }
return {}; return {};
});
} }
BulkFileWatcher::BulkFileWatcher(QObject* parent) BulkFileWatcher::BulkFileWatcher(QObject* parent)