Skip to content

Commit

Permalink
Merge pull request #835 from vkrause/work/vkrause/fix-download-to-tem…
Browse files Browse the repository at this point in the history
…porary-location

Fix downloading encrypted files to a temporary location
  • Loading branch information
vkrause authored Nov 24, 2024
2 parents 09147f9 + 3ff866d commit e579e0b
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions Quotient/jobs/downloadfilejob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QFile> 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();
}
Expand Down

0 comments on commit e579e0b

Please sign in to comment.