diff --git a/src/core/Database.cpp b/src/core/Database.cpp index b25183118..3b499e8e6 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -434,16 +434,23 @@ bool Database::performSave(const QString& filePath, SaveAction action, const QSt break; } case DirectWrite: { + QBuffer dbBuffer; + dbBuffer.open(QIODevice::WriteOnly); + HashingStream hashingStream(&dbBuffer, QCryptographicHash::Md5, kFileBlockToHashSizeBytes); + if (!hashingStream.open(QIODevice::WriteOnly)) { + if (error) { + *error = hashingStream.errorString(); + } + return false; + } + if (!writeDatabase(&hashingStream, error)) { + return false; + } + // Open the original database file for direct-write QFile dbFile(filePath); if (dbFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - HashingStream hashingStream(&dbFile, QCryptographicHash::Md5, kFileBlockToHashSizeBytes); - if (!hashingStream.open(QIODevice::WriteOnly)) { - return false; - } - if (!writeDatabase(&hashingStream, error)) { - return false; - } + dbFile.write(dbBuffer.data()); dbFile.close(); // store the new hash m_fileBlockHash = hashingStream.hashingResult();