1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-12 07:48:04 +00:00

Flush manually when saving a file

This is to work around https://bugreports.qt.io/browse/QTBUG-75077
This commit is contained in:
Chocobo1 2021-09-15 21:50:23 +08:00
parent 21f72baae2
commit fa8786e230
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C

View File

@ -69,7 +69,7 @@ Utils::IO::FileDeviceOutputIterator &Utils::IO::FileDeviceOutputIterator::operat
nonstd::expected<void, QString> Utils::IO::saveToFile(const QString &path, const QByteArray &data)
{
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 {};
}
@ -81,7 +81,7 @@ nonstd::expected<void, QString> Utils::IO::saveToFile(const QString &path, const
return nonstd::make_unexpected(file.errorString());
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 {};