From 144076675cf2bf0b357458a39e40c2c45d3ae1ca Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 13 Feb 2026 13:20:45 +0100 Subject: [PATCH] steamgriddb: save covers atomically --- src/steamgriddb.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/steamgriddb.cpp b/src/steamgriddb.cpp index 4281401..c93e0d6 100644 --- a/src/steamgriddb.cpp +++ b/src/steamgriddb.cpp @@ -8,11 +8,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include @@ -297,16 +297,28 @@ void SteamGridDB::onImageDownloaded() QString coversPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/covers"); QDir dir(coversPath); if (!dir.exists()) { - dir.mkpath(coversPath); + if (!dir.mkpath(coversPath)) { + Q_EMIT fetchError(game, QStringLiteral("Failed to create covers directory")); + m_processedGames++; + Q_EMIT fetchProgress(m_processedGames, m_totalGames); + processNextGame(); + return; + } } QString fileName = game->id() + QStringLiteral(".jpg"); QString filePath = coversPath + QStringLiteral("/") + fileName; - QFile file(filePath); - if (file.open(QIODevice::WriteOnly)) { - file.write(reply->readAll()); - file.close(); + const QByteArray payload = reply->readAll(); + QSaveFile file(filePath); + if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + if (file.write(payload) != payload.size() || !file.commit()) { + Q_EMIT fetchError(game, QStringLiteral("Failed to save cover image")); + m_processedGames++; + Q_EMIT fetchProgress(m_processedGames, m_totalGames); + processNextGame(); + return; + } QUrl localUrl = QUrl::fromLocalFile(filePath); game->setCoverUrl(localUrl);