mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 08:48:07 -06: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:
@@ -46,14 +46,13 @@ namespace
|
||||
if (!filePath.isEmpty())
|
||||
return Utils::IO::saveToFile(filePath, replyData).has_value();
|
||||
|
||||
QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"};
|
||||
tmpfile.setAutoRemove(false);
|
||||
|
||||
if (!tmpfile.open())
|
||||
QTemporaryFile file {Utils::Fs::tempPath()};
|
||||
if (!file.open() || (file.write(replyData) != replyData.length()) || !file.flush())
|
||||
return false;
|
||||
|
||||
filePath = tmpfile.fileName();
|
||||
return (tmpfile.write(replyData) == replyData.length());
|
||||
file.setAutoRemove(false);
|
||||
filePath = file.fileName();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user