From d3e396f7ecd3bcf2df30d2ba203b3548cf6ab5e0 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 17 Oct 2023 20:35:54 +0200 Subject: added command line option to start server clean (#481) when specified with `--clean`, the data directory will be wiped clean at startup --- src/zenserver/zenserver.cpp | 68 +++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 30 deletions(-) (limited to 'src/zenserver/zenserver.cpp') 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) -- cgit v1.2.3