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

Function skeleton_proto

libatomic/src/daemon/sandbox_wire.rs:121–172  ·  view source on GitHub ↗

A kernel skeleton on the wire, with `snapshot` the view's and `live` its rendered tree (inode → path) when the caller has it.

(
    skeleton: &SandboxSkeleton,
    snapshot: pb::ViewSnapshot,
    live: Option<&BTreeMap<u64, String>>,
)

Source from the content-addressed store, hash-verified

119/// A kernel skeleton on the wire, with `snapshot` the view's and `live` its
120/// rendered tree (inode → path) when the caller has it.
121pub fn skeleton_proto(
122 skeleton: &SandboxSkeleton,
123 snapshot: pb::ViewSnapshot,
124 live: Option<&BTreeMap<u64, String>>,
125) -> Result<pb::SandboxSkeleton, String> {
126 let names: HashMap<u64, &str> = std::iter::once(&skeleton.view)
127 .chain(&skeleton.ancestors)
128 .map(|v| (v.id, v.name.as_str()))
129 .collect();
130 let rows = match live {
131 Some(live) => live
132 .iter()
133 .map(|(inode, path)| pb::SandboxViewRow {
134 path: path.clone(),
135 inode: *inode,
136 content: None,
137 })
138 .collect(),
139 None => skeleton
140 .rows
141 .tree
142 .iter()
143 .map(|(path, inode)| pb::SandboxViewRow {
144 path: path.clone(),
145 inode: *inode,
146 content: None,
147 })
148 .collect(),
149 };
150 Ok(pb::SandboxSkeleton {
151 rows,
152 ancestors: skeleton
153 .ancestors
154 .iter()
155 .map(|a| pb::SandboxAncestorView {
156 view: a.name.clone(),
157 head: None,
158 real_state: Some(hash_proto(&a.state)),
159 parent: a.parent.and_then(|p| names.get(&p)).map(|n| n.to_string()),
160 snapshot: None,
161 log: Vec::new(),
162 })
163 .collect(),
164 graph_slice: Some(versioned(
165 SANDBOX_SKELETON_SCHEMA,
166 skeleton.to_bytes().map_err(|e| e.to_string())?,
167 )),
168 snapshot: Some(snapshot),
169 own_log: Vec::new(),
170 vault: None,
171 })
172}
173
174/// What a cache imports from a [`pb::SandboxSkeleton`].
175pub fn skeleton_from_proto(skeleton: &pb::SandboxSkeleton) -> Result<SandboxSkeleton, String> {

Callers 2

materializeMethod · 0.85
submit_changeMethod · 0.85

Calls 8

versionedFunction · 0.85
hash_protoFunction · 0.70
getMethod · 0.65
collectMethod · 0.45
as_strMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
to_bytesMethod · 0.45

Tested by

no test coverage detected