From 0bbbff95cd2bd33bd6a0cad70ce351d9e14454c6 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 14 Feb 2018 11:38:18 -0800 Subject: [PATCH] Fix replacement octree data not working --- assignment-client/src/octree/OctreeServer.h | 2 -- domain-server/src/DomainServer.cpp | 22 ++++++++++++++------- libraries/octree/src/OctreeUtils.cpp | 8 ++------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/assignment-client/src/octree/OctreeServer.h b/assignment-client/src/octree/OctreeServer.h index eab71647e3..e7efc731f2 100644 --- a/assignment-client/src/octree/OctreeServer.h +++ b/assignment-client/src/octree/OctreeServer.h @@ -176,8 +176,6 @@ protected: UniqueSendThread createSendThread(const SharedNodePointer& node); virtual UniqueSendThread newSendThread(const SharedNodePointer& node); - //void replaceContentFromMessageData(QByteArray content); - int _argc; const char** _argv; char** _parsedArgV; diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 8f0e26375e..3eb1f21da0 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -3234,15 +3234,23 @@ void DomainServer::maybeHandleReplacementEntityFile() { } else { qCDebug(domain_server) << "Replacing existing entity date with replacement file"; - data.resetIdAndVersion(); - auto gzippedData = data.toGzippedByteArray(); - - QFile currentFile(getEntitiesFilePath()); - if (!currentFile.open(QIODevice::WriteOnly)) { + QFile replacementFile(replacementFilePath); + if (!replacementFile.remove()) { + // If we can't remove the replacement file, we are at risk of getting into a state where + // we continually replace the primary entity file with the replacement entity file. qCWarning(domain_server) - << "Failed to update entities data file with replacement file, unable to open entities file for writing"; + << "Unable to remove replacement file, bailing"; } else { - currentFile.write(gzippedData); + data.resetIdAndVersion(); + auto gzippedData = data.toGzippedByteArray(); + + QFile currentFile(getEntitiesFilePath()); + if (!currentFile.open(QIODevice::WriteOnly)) { + qCWarning(domain_server) + << "Failed to update entities data file with replacement file, unable to open entities file for writing"; + } else { + currentFile.write(gzippedData); + } } } } diff --git a/libraries/octree/src/OctreeUtils.cpp b/libraries/octree/src/OctreeUtils.cpp index 85ea3beb86..739c2661b3 100644 --- a/libraries/octree/src/OctreeUtils.cpp +++ b/libraries/octree/src/OctreeUtils.cpp @@ -93,12 +93,7 @@ bool OctreeUtils::readOctreeFile(QString path, QJsonDocument* doc) { QByteArray data = file.readAll(); QByteArray jsonData; - if (path.endsWith(".json.gz")) { - if (!gunzip(data, jsonData)) { - qCritical() << "json File not in gzip format: " << path; - return false; - } - } else { + if (!gunzip(data, jsonData)) { jsonData = data; } @@ -173,4 +168,5 @@ QByteArray OctreeUtils::RawOctreeData::toGzippedByteArray() { void OctreeUtils::RawOctreeData::resetIdAndVersion() { id = QUuid::createUuid(); version = OctreeUtils::INITIAL_VERSION; + qDebug() << "Reset octree data to: " << id << version; } \ No newline at end of file