From 4f1f609b55936daa7d6a981e90da53217b1ada41 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 27 Apr 2026 20:51:06 +1000 Subject: [PATCH] fix: use QSaveFile for atomic writes --- .../Caelestia/Images/cachingimageprovider.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/plugin/src/Caelestia/Images/cachingimageprovider.cpp b/plugin/src/Caelestia/Images/cachingimageprovider.cpp index ed726018..8491b641 100644 --- a/plugin/src/Caelestia/Images/cachingimageprovider.cpp +++ b/plugin/src/Caelestia/Images/cachingimageprovider.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include Q_LOGGING_CATEGORY(lcCProv, "caelestia.images.cacheprovider", QtInfoMsg) @@ -152,11 +153,20 @@ private: m_image = canvas; } + // Save to cache const QString parent = QFileInfo(cache).absolutePath(); - if (QDir().mkpath(parent) && m_image.save(cache)) - qCDebug(lcCProv).noquote() << "Saved to" << cache; - else - qCWarning(lcCProv).noquote() << "Failed to save to" << cache; + if (!QDir().mkpath(parent)) { + qCWarning(lcCProv).noquote() << "Failed to create cache dir" << parent; + return; + } + + QSaveFile saveFile(cache); + if (!saveFile.open(QIODevice::WriteOnly) || !m_image.save(&saveFile, "PNG") || !saveFile.commit()) { + qCWarning(lcCProv).noquote() << "Failed to save to" << cache << ":" << saveFile.errorString(); + return; + } + + qCDebug(lcCProv).noquote() << "Saved to" << cache; } QString m_id;