Use QSaveFile for more robust shader disk cache

Task-number: QTBUG-55496
Change-Id: Ie9bd4390e7bb7bf22dbe597a6a01fecec7a6b404
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Laszlo Agocs 2016-11-25 13:56:57 +01:00
parent 7cdc6c9942
commit f0e60aefa4

View File

@ -42,6 +42,7 @@
#include <QOpenGLExtraFunctions>
#include <QStandardPaths>
#include <QDir>
#include <QSaveFile>
#include <QLoggingCategory>
#ifdef Q_OS_UNIX
@ -322,11 +323,14 @@ void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId)
return;
}
QFile f(cacheFileName(cacheKey));
if (f.open(QIODevice::WriteOnly | QIODevice::Truncate))
QSaveFile f(cacheFileName(cacheKey));
if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
f.write(blob);
else
qCDebug(DBG_SHADER_CACHE, "Failed to write %s to shader cache", qPrintable(f.fileName()));
if (!f.commit())
qCDebug(DBG_SHADER_CACHE, "Failed to write %s to shader cache", qPrintable(f.fileName()));
} else {
qCDebug(DBG_SHADER_CACHE, "Failed to create %s in shader cache", qPrintable(f.fileName()));
}
}
QT_END_NAMESPACE