Skip to content

Commit

Permalink
Ensure headers are maintained when converting manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
  • Loading branch information
rydrman committed Feb 1, 2024
1 parent 9c2422e commit 4b19d9c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crates/spfs/src/graph/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
16 changes: 16 additions & 0 deletions crates/spfs/src/graph/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -638,6 +648,12 @@ impl std::ops::Deref for HeaderBuf {
}
}

impl std::borrow::Borrow<Header> for HeaderBuf {
fn borrow(&self) -> &Header {
self
}
}

impl AsRef<Header> for HeaderBuf {
#[inline]
fn as_ref(&self) -> &Header {
Expand Down
6 changes: 5 additions & 1 deletion crates/spfs/src/tracking/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ impl<T> Manifest<T> {
}
}

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;
}
Expand Down
3 changes: 3 additions & 0 deletions crates/spk-build/src/build/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4b19d9c

Please sign in to comment.