From fa8786e230bec2f62d295466fbdb923a04ae639c Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 15 Sep 2021 21:50:23 +0800 Subject: [PATCH] Flush manually when saving a file This is to work around https://bugreports.qt.io/browse/QTBUG-75077 --- src/base/utils/io.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/utils/io.cpp b/src/base/utils/io.cpp index 00aa7df9d..4a9459770 100644 --- a/src/base/utils/io.cpp +++ b/src/base/utils/io.cpp @@ -69,7 +69,7 @@ Utils::IO::FileDeviceOutputIterator &Utils::IO::FileDeviceOutputIterator::operat nonstd::expected 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 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 {};