MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / manifest_from_pack

Function manifest_from_pack

atomic-cli/src/commands/pull/command.rs:66–101  ·  view source on GitHub ↗

Reconstruct a view's manifest from a pulled [`SyncPack`]: find the view's ref target, then its view-snapshot object, and render the manifest text. Returns `None` when the pack carries no ref/snapshot for `name` (the remote view does not exist). This replaces the per-object `get_view_ref` + `get_object("views", …)` round-trips: a pull now reads the remote's view state from the single `/code` sync

(pack: &SyncPack, name: &str, url: &str)

Source from the content-addressed store, hash-verified

64/// round-trips: a pull now reads the remote's view state from the single `/code`
65/// sync response.
66fn manifest_from_pack(pack: &SyncPack, name: &str, url: &str) -> CliResult<Option<ViewManifest>> {
67 let target = match pack.refs.iter().find(|r| r.name == name) {
68 Some(r) => r.new_target.clone(),
69 None => return Ok(None),
70 };
71 let snapshot = pack
72 .objects
73 .iter()
74 .find(|o| o.family == ObjectFamily::View && o.key == target)
75 .and_then(|o| ViewSnapshot::from_bytes(&o.bytes));
76 let snapshot = match snapshot {
77 Some(s) => s,
78 None => return Ok(None),
79 };
80 let manifest = ViewManifest::parse(&snapshot.to_manifest_text(name)).map_err(|e| {
81 CliError::RemoteError {
82 message: format!("Corrupt manifest for view '{name}': {e}"),
83 url: Some(url.to_string()),
84 }
85 })?;
86 // O(1) producer-integrity cross-check: the snapshot's declared `own_set_id`
87 // must equal the order-invariant fold of its own change list. Content
88 // addressing guarantees the object's bytes, but not that a (buggy) producer
89 // minted a self-consistent set-id; this catches that cheaply.
90 let mut fold = SetId::ZERO;
91 for h in &manifest.changes {
92 fold = fold.add(h);
93 }
94 if fold.to_base32() != snapshot.own_set_id {
95 print_warning(&format!(
96 "Remote view '{name}' snapshot set-id disagrees with its change list; \
97 the remote object may be inconsistent."
98 ));
99 }
100 Ok(Some(manifest))
101}
102
103/// Index a pack's objects of one family into `content key → bytes`.
104fn pack_objects_by_key(pack: &SyncPack, family: ObjectFamily) -> HashMap<String, Vec<u8>> {

Callers 1

manifest_chain_from_packFunction · 0.70

Calls 7

print_warningFunction · 0.85
to_manifest_textMethod · 0.80
parseFunction · 0.50
iterMethod · 0.45
cloneMethod · 0.45
addMethod · 0.45
to_base32Method · 0.45

Tested by

no test coverage detected