mirror of
https://github.com/lubosz/overte.git
synced 2025-05-28 06:31:54 +02:00
Merge pull request #13535 from huffman/fix/asset-server-corrupt-mappings
Fix potential map.json corruption in Asset Server
This commit is contained in:
commit
db109589f6
1 changed files with 8 additions and 3 deletions
|
@ -23,6 +23,7 @@
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QJsonDocument>
|
#include <QtCore/QJsonDocument>
|
||||||
|
#include <QtCore/QSaveFile>
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
#include <QtGui/QImageReader>
|
#include <QtGui/QImageReader>
|
||||||
#include <QtCore/QVector>
|
#include <QtCore/QVector>
|
||||||
|
@ -1042,7 +1043,7 @@ bool AssetServer::loadMappingsFromFile() {
|
||||||
bool AssetServer::writeMappingsToFile() {
|
bool AssetServer::writeMappingsToFile() {
|
||||||
auto mapFilePath = _resourcesDirectory.absoluteFilePath(MAP_FILE_NAME);
|
auto mapFilePath = _resourcesDirectory.absoluteFilePath(MAP_FILE_NAME);
|
||||||
|
|
||||||
QFile mapFile { mapFilePath };
|
QSaveFile mapFile { mapFilePath };
|
||||||
if (mapFile.open(QIODevice::WriteOnly)) {
|
if (mapFile.open(QIODevice::WriteOnly)) {
|
||||||
QJsonObject root;
|
QJsonObject root;
|
||||||
|
|
||||||
|
@ -1053,8 +1054,12 @@ bool AssetServer::writeMappingsToFile() {
|
||||||
QJsonDocument jsonDocument { root };
|
QJsonDocument jsonDocument { root };
|
||||||
|
|
||||||
if (mapFile.write(jsonDocument.toJson()) != -1) {
|
if (mapFile.write(jsonDocument.toJson()) != -1) {
|
||||||
qCDebug(asset_server) << "Wrote JSON mappings to file at" << mapFilePath;
|
if (mapFile.commit()) {
|
||||||
return true;
|
qCDebug(asset_server) << "Wrote JSON mappings to file at" << mapFilePath;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
qCWarning(asset_server) << "Failed to commit JSON mappings to file at" << mapFilePath;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qCWarning(asset_server) << "Failed to write JSON mappings to file at" << mapFilePath;
|
qCWarning(asset_server) << "Failed to write JSON mappings to file at" << mapFilePath;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue