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 <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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue