Browse Source

Flush manually when saving a file

This is to work around https://bugreports.qt.io/browse/QTBUG-75077
adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
fa8786e230
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 4
      src/base/utils/io.cpp

4
src/base/utils/io.cpp

@ -69,7 +69,7 @@ Utils::IO::FileDeviceOutputIterator &Utils::IO::FileDeviceOutputIterator::operat
nonstd::expected<void, QString> Utils::IO::saveToFile(const QString &path, const QByteArray &data) nonstd::expected<void, QString> Utils::IO::saveToFile(const QString &path, const QByteArray &data)
{ {
QSaveFile file {path}; QSaveFile file {path};
if (!file.open(QIODevice::WriteOnly) || (file.write(data) != data.size()) || !file.commit()) if (!file.open(QIODevice::WriteOnly) || (file.write(data) != data.size()) || !file.flush() || !file.commit())
return nonstd::make_unexpected(file.errorString()); return nonstd::make_unexpected(file.errorString());
return {}; return {};
} }
@ -81,7 +81,7 @@ nonstd::expected<void, QString> Utils::IO::saveToFile(const QString &path, const
return nonstd::make_unexpected(file.errorString()); return nonstd::make_unexpected(file.errorString());
const int bencodedDataSize = lt::bencode(Utils::IO::FileDeviceOutputIterator {file}, data); const int bencodedDataSize = lt::bencode(Utils::IO::FileDeviceOutputIterator {file}, data);
if ((file.size() != bencodedDataSize) || !file.commit()) if ((file.size() != bencodedDataSize) || !file.flush() || !file.commit())
return nonstd::make_unexpected(file.errorString()); return nonstd::make_unexpected(file.errorString());
return {}; return {};

Loading…
Cancel
Save