mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 05:27:15 +03:00
Improve handling when writing to temporary files
Let QTemporaryFile remove incomplete written file when error occurs. "XXXXXX" template is not strictly required according to Qt doc.
This commit is contained in:
parent
fa8786e230
commit
9673be17cb
1 changed files with 5 additions and 6 deletions
|
@ -46,14 +46,13 @@ namespace
|
||||||
if (!filePath.isEmpty())
|
if (!filePath.isEmpty())
|
||||||
return Utils::IO::saveToFile(filePath, replyData).has_value();
|
return Utils::IO::saveToFile(filePath, replyData).has_value();
|
||||||
|
|
||||||
QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"};
|
QTemporaryFile file {Utils::Fs::tempPath()};
|
||||||
tmpfile.setAutoRemove(false);
|
if (!file.open() || (file.write(replyData) != replyData.length()) || !file.flush())
|
||||||
|
|
||||||
if (!tmpfile.open())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
filePath = tmpfile.fileName();
|
file.setAutoRemove(false);
|
||||||
return (tmpfile.write(replyData) == replyData.length());
|
filePath = file.fileName();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue