From fd532dd597e51b99382a79f1a82647a59940722e Mon Sep 17 00:00:00 2001 From: William Brown Date: Wed, 14 May 2025 15:11:57 +1000 Subject: [PATCH] Fix minor issue with untagged version handling --- server/core/src/config.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/server/core/src/config.rs b/server/core/src/config.rs index bd1a700876..bae84779b8 100644 --- a/server/core/src/config.rs +++ b/server/core/src/config.rs @@ -21,17 +21,19 @@ use url::Url; use crate::repl::config::ReplicationConfiguration; #[derive(Debug, Deserialize)] -#[serde(untagged)] -enum VersionDetection { - Version(Version), - Legacy, +struct VersionDetection { + #[serde(default)] + version: Version, } -#[derive(Debug, Deserialize)] -#[serde(tag = "version")] +#[derive(Debug, Deserialize, Default)] +// #[serde(tag = "version")] pub enum Version { #[serde(rename = "2")] V2, + + #[default] + Legacy, } // Allowed as the large enum is only short lived at startup to the true config @@ -303,8 +305,9 @@ impl ServerConfigUntagged { })?; // First, can we detect the config version? - let config_version = - toml::from_str::(contents.as_str()).map_err(|err| { + let config_version = toml::from_str::(contents.as_str()) + .map(|vd| vd.version) + .map_err(|err| { eprintln!( "Unable to parse config version from '{:?}': {:?}", config_path.as_ref(), @@ -314,11 +317,9 @@ impl ServerConfigUntagged { })?; match config_version { - VersionDetection::Version(Version::V2) => { - toml::from_str::(contents.as_str()) - .map(|values| ServerConfigUntagged::Version(ServerConfigVersion::V2 { values })) - } - VersionDetection::Legacy => { + Version::V2 => toml::from_str::(contents.as_str()) + .map(|values| ServerConfigUntagged::Version(ServerConfigVersion::V2 { values })), + Version::Legacy => { toml::from_str::(contents.as_str()).map(ServerConfigUntagged::Legacy) } }