Browse Source

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.
adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
9673be17cb
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 11
      src/base/net/downloadhandlerimpl.cpp

11
src/base/net/downloadhandlerimpl.cpp

@ -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…
Cancel
Save