mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 12:53:44 +02:00
CR
This commit is contained in:
parent
80b03b9046
commit
8a69c69bec
6 changed files with 23 additions and 35 deletions
|
@ -79,14 +79,14 @@ private:
|
|||
#include <quazip5/quazipfile.h>
|
||||
class EntitiesBackupHandler {
|
||||
public:
|
||||
EntitiesBackupHandler(QString entitiesFilePath) : _entitiesFilePath(entitiesFilePath) {}
|
||||
EntitiesBackupHandler(QString entitiesFilePath, QString entitiesReplacementFilePath)
|
||||
: _entitiesFilePath(entitiesFilePath)
|
||||
, _entitiesReplacementFilePath {}
|
||||
|
||||
void loadBackup(QuaZip& zip) {}
|
||||
|
||||
// Create a skeleton backup
|
||||
void createBackup(QuaZip& zip) {
|
||||
qDebug() << "Creating a backup from handler";
|
||||
|
||||
QFile entitiesFile { _entitiesFilePath };
|
||||
|
||||
if (entitiesFile.open(QIODevice::ReadOnly)) {
|
||||
|
@ -95,7 +95,7 @@ public:
|
|||
zipFile.write(entitiesFile.readAll());
|
||||
zipFile.close();
|
||||
if (zipFile.getZipError() != UNZ_OK) {
|
||||
qDebug() << "Failed to zip models.json.gz: " << zipFile.getZipError();
|
||||
qCritical() << "Failed to zip models.json.gz: " << zipFile.getZipError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,12 +108,12 @@ public:
|
|||
}
|
||||
QuaZipFile zipFile { &zip };
|
||||
if (!zipFile.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "Failed to open models.json.gz in backup";
|
||||
qCritical() << "Failed to open models.json.gz in backup";
|
||||
return;
|
||||
}
|
||||
auto data = zipFile.readAll();
|
||||
|
||||
QFile entitiesFile { _entitiesFilePath };
|
||||
QFile entitiesFile { _entitiesReplacementFilePath };
|
||||
|
||||
if (entitiesFile.open(QIODevice::WriteOnly)) {
|
||||
entitiesFile.write(data);
|
||||
|
@ -122,7 +122,7 @@ public:
|
|||
zipFile.close();
|
||||
|
||||
if (zipFile.getZipError() != UNZ_OK) {
|
||||
qDebug() << "Failed to zip models.json.gz: " << zipFile.getZipError();
|
||||
qCritical() << "Failed to zip models.json.gz: " << zipFile.getZipError();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,6 +136,7 @@ public:
|
|||
|
||||
private:
|
||||
QString _entitiesFilePath;
|
||||
QString _entitiesReplacementFilePath;
|
||||
};
|
||||
|
||||
#endif /* hifi_BackupHandler_h */
|
||||
|
|
|
@ -35,10 +35,10 @@
|
|||
const int DomainContentBackupManager::DEFAULT_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds
|
||||
|
||||
// Backup format looks like: daily_backup-TIMESTAMP.zip
|
||||
const static QString DATETIME_FORMAT { "yyyy-MM-dd_HH-mm-ss" };
|
||||
const static QString DATETIME_FORMAT_RE("\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}");
|
||||
static const QString AUTOMATIC_BACKUP_PREFIX{ "autobackup-" };
|
||||
static const QString MANUAL_BACKUP_PREFIX{ "backup-" };
|
||||
static const QString DATETIME_FORMAT { "yyyy-MM-dd_HH-mm-ss" };
|
||||
static const QString DATETIME_FORMAT_RE { "\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}" };
|
||||
static const QString AUTOMATIC_BACKUP_PREFIX { "autobackup-" };
|
||||
static const QString MANUAL_BACKUP_PREFIX { "backup-" };
|
||||
void DomainContentBackupManager::addBackupHandler(BackupHandler handler) {
|
||||
_backupHandlers.push_back(std::move(handler));
|
||||
}
|
||||
|
@ -131,14 +131,6 @@ void DomainContentBackupManager::setup() {
|
|||
}
|
||||
|
||||
bool DomainContentBackupManager::process() {
|
||||
if (!_initialLoadComplete) {
|
||||
QDir backupDir { _backupDirectory };
|
||||
if (!backupDir.exists()) {
|
||||
backupDir.mkpath(".");
|
||||
}
|
||||
_initialLoadComplete = true;
|
||||
}
|
||||
|
||||
if (isStillRunning()) {
|
||||
constexpr int64_t MSECS_TO_USECS = 1000;
|
||||
constexpr int64_t USECS_TO_SLEEP = 10 * MSECS_TO_USECS; // every 10ms
|
||||
|
@ -219,12 +211,9 @@ void DomainContentBackupManager::deleteBackup(MiniPromise::Promise promise, cons
|
|||
return;
|
||||
}
|
||||
|
||||
bool success { false };
|
||||
QDir backupDir { _backupDirectory };
|
||||
QFile backupFile { backupDir.filePath(backupName) };
|
||||
if (backupFile.remove()) {
|
||||
success = true;
|
||||
}
|
||||
auto success = backupFile.remove();
|
||||
promise->resolve({
|
||||
{ "success", success }
|
||||
});
|
||||
|
@ -237,7 +226,7 @@ void DomainContentBackupManager::recoverFromBackup(MiniPromise::Promise promise,
|
|||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Recoving from" << backupName;
|
||||
qDebug() << "Recovering from" << backupName;
|
||||
|
||||
bool success { false };
|
||||
QDir backupDir { _backupDirectory };
|
||||
|
|
|
@ -51,7 +51,6 @@ public:
|
|||
bool debugTimestampNow = false);
|
||||
|
||||
void addBackupHandler(BackupHandler handler);
|
||||
bool isInitialLoadComplete() const { return _initialLoadComplete; }
|
||||
std::vector<BackupItemInfo> getAllBackups();
|
||||
|
||||
void aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist
|
||||
|
@ -86,7 +85,6 @@ private:
|
|||
const QString _backupDirectory;
|
||||
std::vector<BackupHandler> _backupHandlers;
|
||||
int _persistInterval { 0 };
|
||||
bool _initialLoadComplete { false };
|
||||
|
||||
int64_t _lastCheck { 0 };
|
||||
std::vector<BackupRule> _backupRules;
|
||||
|
|
|
@ -296,7 +296,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
maybeHandleReplacementEntityFile();
|
||||
|
||||
_contentManager.reset(new DomainContentBackupManager(getContentBackupDir(), _settingsManager.settingsResponseObjectForType("6")["entity_server_settings"].toObject()));
|
||||
_contentManager->addBackupHandler(new EntitiesBackupHandler(getEntitiesFilePath()));
|
||||
_contentManager->addBackupHandler(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath()));
|
||||
_contentManager->addBackupHandler(new BackupSupervisor(getContentBackupDir()));
|
||||
_contentManager->initialize(true);
|
||||
|
||||
|
@ -1936,7 +1936,6 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
const QString URI_API_BACKUPS = "/api/backups";
|
||||
const QString URI_API_BACKUPS_ID = "/api/backups/";
|
||||
const QString URI_API_BACKUPS_RECOVER = "/api/backups/recover/";
|
||||
//const QString URI_API_BACKUPS_CREATE = "/api/backups";
|
||||
|
||||
const QString UUID_REGEX_STRING = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
||||
|
||||
|
@ -2127,9 +2126,11 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
auto deferred = makePromise("recoverFromBackup");
|
||||
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||
QJsonObject rootJSON;
|
||||
rootJSON["success"] = result["success"].toBool();
|
||||
auto success = result["success"].toBool();
|
||||
rootJSON["success"] = success;
|
||||
QJsonDocument docJSON(rootJSON);
|
||||
connection->respond(HTTPConnection::StatusCode200, docJSON.toJson(), JSON_MIME_TYPE.toUtf8());
|
||||
connection->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
||||
JSON_MIME_TYPE.toUtf8());
|
||||
});
|
||||
_contentManager->recoverFromBackup(deferred, id);
|
||||
return true;
|
||||
|
@ -2258,7 +2259,6 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
return true;
|
||||
|
||||
} else if (url.path() == URI_API_BACKUPS) {
|
||||
qDebug() << "GOt request to create a backup:";
|
||||
auto params = connection->parseUrlEncodedForm();
|
||||
auto it = params.find("name");
|
||||
if (it == params.end()) {
|
||||
|
@ -2374,9 +2374,11 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
auto deferred = makePromise("deleteBackup");
|
||||
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||
QJsonObject rootJSON;
|
||||
rootJSON["success"] = result["success"].toBool();
|
||||
auto success = result["success"].toBool();
|
||||
rootJSON["success"] = success;
|
||||
QJsonDocument docJSON(rootJSON);
|
||||
connection->respond(HTTPConnection::StatusCode200, docJSON.toJson(), JSON_MIME_TYPE.toUtf8());
|
||||
connection->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
||||
JSON_MIME_TYPE.toUtf8());
|
||||
});
|
||||
_contentManager->deleteBackup(deferred, id);
|
||||
|
||||
|
|
|
@ -287,7 +287,6 @@ void HTTPConnection::readContent() {
|
|||
if (_socket->bytesAvailable() < size) {
|
||||
return;
|
||||
}
|
||||
qDebug() << "Reading content";
|
||||
_socket->read(_requestContent.data(), size);
|
||||
_socket->disconnect(this, SLOT(readContent()));
|
||||
|
||||
|
|
|
@ -2246,7 +2246,6 @@ bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer
|
|||
}
|
||||
entityDescription["DataVersion"] = _persistDataVersion;
|
||||
entityDescription["Id"] = _persistID;
|
||||
qDebug() << "Writing to map: " << _persistDataVersion << _persistID;
|
||||
QScriptEngine scriptEngine;
|
||||
RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine, skipDefaultValues,
|
||||
skipThoseWithBadParents, _myAvatar);
|
||||
|
|
Loading…
Reference in a new issue