From a483cc97d56a770c4ccf91dfccf790a8c2d0c9fa Mon Sep 17 00:00:00 2001 From: Kim Altintop Date: Wed, 29 Mar 2023 13:20:08 +0200 Subject: core: version each metadata type separately It turns out to be preferable to be able to break one type without affecting the other. So instead of the global SpecVersion, use a separate FmtVersion for each type. For compatibility, keep supporting spec_version fields (until next major bump of the respective types' version). Signed-off-by: Kim Altintop --- src/metadata/drop.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'src/metadata/drop.rs') diff --git a/src/metadata/drop.rs b/src/metadata/drop.rs index d231712..1341f68 100644 --- a/src/metadata/drop.rs +++ b/src/metadata/drop.rs @@ -10,6 +10,7 @@ use std::{ }, io, num::NonZeroUsize, + ops::Deref, }; use log::warn; @@ -32,7 +33,6 @@ use super::{ Mirrors, Signature, Signed, - SpecVersion, }; use crate::{ git::Refname, @@ -40,6 +40,25 @@ use crate::{ str::Varchar, }; +pub const FMT_VERSION: FmtVersion = FmtVersion(super::FmtVersion::new(0, 2, 0)); + +#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] +pub struct FmtVersion(super::FmtVersion); + +impl Deref for FmtVersion { + type Target = super::FmtVersion; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl Default for FmtVersion { + fn default() -> Self { + FMT_VERSION + } +} + #[derive(Clone, serde::Serialize, serde::Deserialize)] pub struct Roles { pub root: Role, @@ -83,9 +102,10 @@ pub struct Annotated { pub type Verified = super::Verified; -#[derive(Clone, serde::Serialize, serde::Deserialize)] +#[derive(Clone, serde::Deserialize)] pub struct Drop { - pub spec_version: SpecVersion, + #[serde(alias = "spec_version")] + pub fmt_version: FmtVersion, #[serde(default = "Description::new")] pub description: Description, pub prev: Option, @@ -121,7 +141,7 @@ impl Drop { { use error::Verification::*; - if !crate::SPEC_VERSION.is_compatible(&self.spec_version) { + if !FMT_VERSION.is_compatible(&self.fmt_version) { return Err(IncompatibleSpecVersion); } @@ -153,7 +173,7 @@ impl Drop { return Err(Expired); } } - if !crate::SPEC_VERSION.is_compatible(&mirrors.signed.spec_version) { + if !FMT_VERSION.is_compatible(&mirrors.signed.fmt_version) { return Err(IncompatibleSpecVersion); } @@ -177,7 +197,7 @@ impl Drop { return Err(Expired); } } - if !crate::SPEC_VERSION.is_compatible(&alt.signed.spec_version) { + if !FMT_VERSION.is_compatible(&alt.signed.fmt_version) { return Err(IncompatibleSpecVersion); } @@ -203,6 +223,28 @@ impl<'a> From<&'a Drop> for Cow<'a, Drop> { } } +impl serde::Serialize for Drop { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + use serde::ser::SerializeStruct; + + let mut s = serializer.serialize_struct("Drop", 5)?; + let version_field = if self.fmt_version < FMT_VERSION { + "spec_version" + } else { + "fmt_version" + }; + s.serialize_field(version_field, &self.fmt_version)?; + s.serialize_field("description", &self.description)?; + s.serialize_field("prev", &self.prev)?; + s.serialize_field("roles", &self.roles)?; + s.serialize_field("custom", &self.custom)?; + s.end() + } +} + mod verify { use super::*; -- cgit v1.2.3