From 23a279434ca0b15883aab2dd6086974559614679 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 3 Jul 2018 10:33:25 -0700 Subject: [PATCH] Fix potential map.json corruption in Asset Server --- assignment-client/src/assets/AssetServer.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index e0c35b7148..e79473783a 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1042,7 +1043,7 @@ bool AssetServer::loadMappingsFromFile() { bool AssetServer::writeMappingsToFile() { auto mapFilePath = _resourcesDirectory.absoluteFilePath(MAP_FILE_NAME); - QFile mapFile { mapFilePath }; + QSaveFile mapFile { mapFilePath }; if (mapFile.open(QIODevice::WriteOnly)) { QJsonObject root; @@ -1053,8 +1054,12 @@ bool AssetServer::writeMappingsToFile() { QJsonDocument jsonDocument { root }; if (mapFile.write(jsonDocument.toJson()) != -1) { - qCDebug(asset_server) << "Wrote JSON mappings to file at" << mapFilePath; - return true; + if (mapFile.commit()) { + 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 { qCWarning(asset_server) << "Failed to write JSON mappings to file at" << mapFilePath; }