diff --git a/Quotient/jobs/downloadfilejob.cpp b/Quotient/jobs/downloadfilejob.cpp index 5413958cd..28079eb00 100644 --- a/Quotient/jobs/downloadfilejob.cpp +++ b/Quotient/jobs/downloadfilejob.cpp @@ -156,19 +156,15 @@ BaseJob::Status DownloadFileJob::prepareResult() } } else { if (d->encryptedFileMetadata.has_value()) { - QTemporaryFile tempTempFile; // Assuming it to be next to tempFile - decryptFile(*d->tempFile, *d->encryptedFileMetadata, tempTempFile); - d->tempFile->close(); - if (!d->tempFile->remove()) { - qWarning(JOBS) - << "Failed to remove the decrypted file placeholder"; - return { FileError, "Couldn't finalise the download"_L1 }; - } - if (!tempTempFile.rename(d->tempFile->fileName())) { - qWarning(JOBS) << "Failed to rename" << tempTempFile.fileName() - << "to" << d->tempFile->fileName(); - return { FileError, "Couldn't finalise the download"_L1 }; + QScopedPointer tempTempFile(new QTemporaryFile); + if (!tempTempFile->open(QFile::ReadWrite)) { + qCWarning(JOBS) << "Failed to open temporary file for decryption" + << tempTempFile->errorString(); + return { FileError, "Couldn't open temporary file for decryption"_L1 }; } + decryptFile(*d->tempFile, *d->encryptedFileMetadata, *tempTempFile); + d->tempFile.swap(tempTempFile); + d->tempFile->close(); } else { d->tempFile->close(); }