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