mirror of
https://github.com/nomic-ai/gpt4all
synced 2024-11-02 09:40:42 +00:00
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
This commit is contained in:
parent
ee5c58c26c
commit
18fa61c025
@ -286,6 +286,14 @@ void HashAndSaveFile::hashAndSave(const QString &expectedHash, const QString &sa
|
|||||||
// The file save needs the tempFile closed
|
// The file save needs the tempFile closed
|
||||||
tempFile->close();
|
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
|
// Reopen the tempFile for copying
|
||||||
if (!tempFile->open()) {
|
if (!tempFile->open()) {
|
||||||
qWarning() << "ERROR: Could not open temp file at finish:"
|
qWarning() << "ERROR: Could not open temp file at finish:"
|
||||||
|
Loading…
Reference in New Issue
Block a user