fix: use QSaveFile for atomic writes
This commit is contained in:
parent
411e013ea0
commit
4f1f609b55
1 changed files with 14 additions and 4 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
#include <qloggingcategory.h>
|
#include <qloggingcategory.h>
|
||||||
#include <qpainter.h>
|
#include <qpainter.h>
|
||||||
#include <qrunnable.h>
|
#include <qrunnable.h>
|
||||||
|
#include <qsavefile.h>
|
||||||
#include <qthreadpool.h>
|
#include <qthreadpool.h>
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(lcCProv, "caelestia.images.cacheprovider", QtInfoMsg)
|
Q_LOGGING_CATEGORY(lcCProv, "caelestia.images.cacheprovider", QtInfoMsg)
|
||||||
|
|
@ -152,11 +153,20 @@ private:
|
||||||
m_image = canvas;
|
m_image = canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save to cache
|
||||||
const QString parent = QFileInfo(cache).absolutePath();
|
const QString parent = QFileInfo(cache).absolutePath();
|
||||||
if (QDir().mkpath(parent) && m_image.save(cache))
|
if (!QDir().mkpath(parent)) {
|
||||||
qCDebug(lcCProv).noquote() << "Saved to" << cache;
|
qCWarning(lcCProv).noquote() << "Failed to create cache dir" << parent;
|
||||||
else
|
return;
|
||||||
qCWarning(lcCProv).noquote() << "Failed to save to" << cache;
|
}
|
||||||
|
|
||||||
|
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;
|
QString m_id;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue