From 4b19d9c7a8f13bd6630f36f90c9c3cb0903352fe Mon Sep 17 00:00:00 2001 From: Ryan Bottriell Date: Tue, 30 Jan 2024 15:23:32 -0800 Subject: [PATCH] Ensure headers are maintained when converting manifests Signed-off-by: Ryan Bottriell --- crates/spfs/src/graph/manifest.rs | 6 +++++- crates/spfs/src/graph/object.rs | 16 ++++++++++++++++ crates/spfs/src/tracking/manifest.rs | 6 +++++- crates/spk-build/src/build/binary.rs | 3 +++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/spfs/src/graph/manifest.rs b/crates/spfs/src/graph/manifest.rs index e9810acd8..8f2608355 100644 --- a/crates/spfs/src/graph/manifest.rs +++ b/crates/spfs/src/graph/manifest.rs @@ -112,7 +112,11 @@ impl Manifest { } iter_tree(self, self.root(), &mut root); - tracking::Manifest::new(root) + let mut manifest = tracking::Manifest::new(root); + // ensure that the manifest will round-trip in the case of it + // being converted back into this type + manifest.set_header(self.header().to_owned()); + manifest } pub(super) fn legacy_encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> { diff --git a/crates/spfs/src/graph/object.rs b/crates/spfs/src/graph/object.rs index 9894c20ad..8789135ca 100644 --- a/crates/spfs/src/graph/object.rs +++ b/crates/spfs/src/graph/object.rs @@ -539,6 +539,16 @@ impl std::fmt::Debug for Header { } } +impl std::borrow::ToOwned for Header { + type Owned = HeaderBuf; + + fn to_owned(&self) -> Self::Owned { + let mut buf = HeaderBuf(Default::default()); + buf.0[..].clone_from_slice(&self.0); + buf + } +} + impl std::ops::Deref for Header { type Target = [u8]; @@ -638,6 +648,12 @@ impl std::ops::Deref for HeaderBuf { } } +impl std::borrow::Borrow
for HeaderBuf { + fn borrow(&self) -> &Header { + self + } +} + impl AsRef
for HeaderBuf { #[inline] fn as_ref(&self) -> &Header { diff --git a/crates/spfs/src/tracking/manifest.rs b/crates/spfs/src/tracking/manifest.rs index df9d70f02..2419ea696 100644 --- a/crates/spfs/src/tracking/manifest.rs +++ b/crates/spfs/src/tracking/manifest.rs @@ -90,8 +90,12 @@ impl Manifest { } } + pub fn header(&self) -> &graph::object::Header { + &self.header + } + pub fn set_header(&mut self, mut header: graph::object::HeaderBuf) { - // an different object kind would cause bugs and should never be allowed + // a different object kind would cause bugs and should never be allowed header.set_object_kind(graph::ObjectKind::Manifest); self.header = header; } diff --git a/crates/spk-build/src/build/binary.rs b/crates/spk-build/src/build/binary.rs index 7444d883c..bbd8e824c 100644 --- a/crates/spk-build/src/build/binary.rs +++ b/crates/spk-build/src/build/binary.rs @@ -886,6 +886,9 @@ fn split_manifest_by_component( let mut manifests = HashMap::with_capacity(components.len()); for component in components.iter() { let mut component_manifest = spfs::tracking::Manifest::default(); + // ensure we are storing things with the same settings as the + // original manifest that was generated by the build + component_manifest.set_header(manifest.header().to_owned()); // identify all the file paths that we will replicate // first so that we can also identify necessary