From cfff7657310c6e1f7fd85be9cf9bf82b14abe9ad Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 2 Feb 2016 14:21:34 -0800 Subject: [PATCH] allow for absolute path handling at entity-server --- assignment-client/src/octree/OctreeServer.cpp | 27 ++++++++++++------- assignment-client/src/octree/OctreeServer.h | 2 +- .../resources/describe-settings.json | 6 ++--- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index 81e25cc7ba..95c869c874 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -1030,13 +1030,12 @@ void OctreeServer::readConfiguration() { qDebug() << "wantPersist=" << _wantPersist; if (_wantPersist) { - QString persistFilename; - if (!readOptionString(QString("persistFilename"), settingsSectionObject, persistFilename)) { - persistFilename = getMyDefaultPersistFilename(); + if (!readOptionString("persistFilePath", settingsSectionObject, _persistFilePath) + && !readOptionString("persistFilename", settingsSectionObject, _persistFilePath)) { + _persistFilePath = getMyDefaultPersistFilename(); } - strcpy(_persistFilename, qPrintable(persistFilename)); - qDebug("persistFilename=%s", _persistFilename); + qDebug() << "persistFilePath=" << _persistFilePath; _persistAsFileType = "json.gz"; @@ -1145,8 +1144,16 @@ void OctreeServer::domainSettingsRequestComplete() { if (_wantPersist) { // If persist filename does not exist, let's see if there is one beside the application binary // If there is, let's copy it over to our target persist directory - auto persistPath = ServerPathUtils::getDataFilePath("entities/" + QString(_persistFilename)); - if (!QFile::exists(persistPath)) { + QDir persistPath { _persistFilePath }; + QString absoluteFilePath = persistPath.path(); + + if (persistPath.isRelative()) { + // if the domain settings passed us a relative path, make an absolute path that is relative to the + // default data directory + absoluteFilePath = QDir(ServerPathUtils::getDataFilePath("entities/")).absoluteFilePath(_persistFilePath); + } + + if (!QFile::exists(absoluteFilePath)) { qDebug() << "Persist file does not exist, checking for existence of persist file next to application"; static const QString OLD_DEFAULT_PERSIST_FILENAME = "resources/models.json.gz"; @@ -1154,7 +1161,7 @@ void OctreeServer::domainSettingsRequestComplete() { // This is the old persist path, based on the current persist filename, which could // be a custom filename set by the user. - auto oldPersistPath = QDir(oldResourcesDirectory).absoluteFilePath(_persistFilename); + auto oldPersistPath = QDir(oldResourcesDirectory).absoluteFilePath(_persistFilePath); // This is the old default persist path. auto oldDefaultPersistPath = QDir(oldResourcesDirectory).absoluteFilePath(OLD_DEFAULT_PERSIST_FILENAME); @@ -1181,14 +1188,14 @@ void OctreeServer::domainSettingsRequestComplete() { if (shouldCopy) { qDebug() << "Old persist file found, copying from " << pathToCopyFrom << " to " << persistPath; - QFile::copy(pathToCopyFrom, persistPath); + QFile::copy(pathToCopyFrom, absoluteFilePath); } else { qDebug() << "No existing persist file found"; } } // now set up PersistThread - _persistThread = new OctreePersistThread(_tree, persistPath, _persistInterval, + _persistThread = new OctreePersistThread(_tree, absoluteFilePath, _persistInterval, _wantBackup, _settings, _debugTimestampNow, _persistAsFileType); _persistThread->initialize(true); } diff --git a/assignment-client/src/octree/OctreeServer.h b/assignment-client/src/octree/OctreeServer.h index f1aa9531e8..1430715571 100644 --- a/assignment-client/src/octree/OctreeServer.h +++ b/assignment-client/src/octree/OctreeServer.h @@ -169,7 +169,7 @@ protected: int _statusPort; QString _statusHost; - char _persistFilename[MAX_FILENAME_LENGTH]; + QString _persistFilePath; QString _persistAsFileType; int _packetsPerClientPerInterval; int _packetsTotalPerInterval; diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index e38aa2a75a..f024ba5648 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -383,9 +383,9 @@ "assignment-types": [6], "settings": [ { - "name": "persistFilename", - "label": "Entities Filename", - "help": "the path to the file entities are stored in. Make sure the path exists.", + "name": "persistFilePath", + "label": "Entities File Path", + "help": "The path to the file entities are stored in. If path is relative it will be relative to the application data directory.", "placeholder": "models.json.gz", "default": "models.json.gz", "advanced": true