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