Fix replacement octree data not working

This commit is contained in:
Ryan Huffman 2018-02-14 11:38:18 -08:00 committed by Atlante45
parent 2a667fcd60
commit 0bbbff95cd
3 changed files with 17 additions and 15 deletions

View file

@ -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;

View file

@ -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);
}
}
}
}

View file

@ -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;
}