aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/zenserver.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-10-17 20:35:54 +0200
committerGitHub <[email protected]>2023-10-17 20:35:54 +0200
commitd3e396f7ecd3bcf2df30d2ba203b3548cf6ab5e0 (patch)
tree1ff10db41dc5ba53896ebb7cab1ff840010351ba /src/zenserver/zenserver.cpp
parentremoved unnecessary vector in ZenCacheMemoryLayer::Drop (diff)
downloadzen-d3e396f7ecd3bcf2df30d2ba203b3548cf6ab5e0.tar.xz
zen-d3e396f7ecd3bcf2df30d2ba203b3548cf6ab5e0.zip
added command line option to start server clean (#481)
when specified with `--clean`, the data directory will be wiped clean at startup
Diffstat (limited to 'src/zenserver/zenserver.cpp')
-rw-r--r--src/zenserver/zenserver.cpp68
1 files changed, 38 insertions, 30 deletions
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 9d51a581e..60950dbe3 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -308,53 +308,61 @@ ZenServer::InitializeState(const ZenServerOptions& ServerOptions)
bool WipeState = false;
std::string WipeReason = "Unspecified";
+ if (ServerOptions.IsCleanStart)
+ {
+ WipeState = true;
+ WipeReason = "clean start requested";
+ }
+
bool UpdateManifest = false;
std::filesystem::path ManifestPath = m_DataRoot / "root_manifest";
- FileContents ManifestData = ReadFile(ManifestPath);
- if (ManifestData.ErrorCode)
+ if (!WipeState)
{
- if (ServerOptions.IsFirstRun)
- {
- ZEN_INFO("Initializing state at '{}'", m_DataRoot);
+ FileContents ManifestData = ReadFile(ManifestPath);
- UpdateManifest = true;
- }
- else
+ if (ManifestData.ErrorCode)
{
- WipeState = true;
- WipeReason = fmt::format("No manifest present at '{}'", ManifestPath);
- }
- }
- else
- {
- IoBuffer Manifest = ManifestData.Flatten();
-
- if (CbValidateError ValidationResult = ValidateCompactBinary(Manifest, CbValidateMode::All);
- ValidationResult != CbValidateError::None)
- {
- ZEN_WARN("Manifest validation failed: {}, state will be wiped", uint32_t(ValidationResult));
+ if (ServerOptions.IsFirstRun)
+ {
+ ZEN_INFO("Initializing state at '{}'", m_DataRoot);
- WipeState = true;
- WipeReason = fmt::format("Validation of manifest at '{}' failed: {}", ManifestPath, uint32_t(ValidationResult));
+ UpdateManifest = true;
+ }
+ else
+ {
+ WipeState = true;
+ WipeReason = fmt::format("No manifest present at '{}'", ManifestPath);
+ }
}
else
{
- m_RootManifest = LoadCompactBinaryObject(Manifest);
+ IoBuffer Manifest = ManifestData.Flatten();
- const int32_t ManifestVersion = m_RootManifest["schema_version"].AsInt32(0);
-
- if (ManifestVersion != ZEN_CFG_SCHEMA_VERSION)
+ if (CbValidateError ValidationResult = ValidateCompactBinary(Manifest, CbValidateMode::All);
+ ValidationResult != CbValidateError::None)
{
+ ZEN_WARN("Manifest validation failed: {}, state will be wiped", uint32_t(ValidationResult));
+
WipeState = true;
- WipeReason = fmt::format("Manifest schema version: {}, differs from required: {}", ManifestVersion, ZEN_CFG_SCHEMA_VERSION);
+ WipeReason = fmt::format("Validation of manifest at '{}' failed: {}", ManifestPath, uint32_t(ValidationResult));
+ }
+ else
+ {
+ m_RootManifest = LoadCompactBinaryObject(Manifest);
+
+ const int32_t ManifestVersion = m_RootManifest["schema_version"].AsInt32(0);
+
+ if (ManifestVersion != ZEN_CFG_SCHEMA_VERSION)
+ {
+ WipeState = true;
+ WipeReason =
+ fmt::format("Manifest schema version: {}, differs from required: {}", ManifestVersion, ZEN_CFG_SCHEMA_VERSION);
+ }
}
}
}
- // Release any open handles so we can overwrite the manifest
- ManifestData = {};
-
// Handle any state wipe
if (WipeState)