download: atomically move tempfile when possible

should save unnecessary time and I/O and eliminate the possibility
of the file being improperly truncated when the temp file is on
the same filesystem as the destination path
pull/520/head
Aaron Miller 1 year ago committed by AT
parent ee5c58c26c
commit 18fa61c025

@ -286,6 +286,14 @@ void HashAndSaveFile::hashAndSave(const QString &expectedHash, const QString &sa
// The file save needs the tempFile closed
tempFile->close();
// Attempt to *move* the verified tempfile into place - this should be atomic
// but will only work if the destination is on the same filesystem
if (tempFile->rename(saveFilePath)) {
tempFile->setAutoRemove(false);
emit hashAndSaveFinished(true, tempFile, modelReply);
return;
}
// Reopen the tempFile for copying
if (!tempFile->open()) {
qWarning() << "ERROR: Could not open temp file at finish:"

Loading…
Cancel
Save