fix: use QSaveFile for atomic writes

This commit is contained in:
2 * r + 2 * t 2026-04-27 20:51:06 +10:00
parent 411e013ea0
commit 4f1f609b55

View file

@ -9,6 +9,7 @@
#include <qloggingcategory.h>
#include <qpainter.h>
#include <qrunnable.h>
#include <qsavefile.h>
#include <qthreadpool.h>
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;