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

Function pull

libatomic/examples/replication_acceptance/peer.rs:189–256  ·  view source on GitHub ↗
(State(endpoint): State<Endpoint>, headers: HeaderMap, body: Bytes)

Source from the content-addressed store, hash-verified

187 )
188}
189async fn pull(State(endpoint): State<Endpoint>, headers: HeaderMap, body: Bytes) -> Response {
190 if !supported(&headers) {
191 return error("acceptance endpoint requires actual binary sync protocol");
192 }
193 let wants = match SyncWants::decode(&body) {
194 Ok(w) => w,
195 Err(e) => return error(e),
196 };
197 let store = endpoint.store.lock().unwrap();
198 let mut names: BTreeSet<String> = if wants.refs.is_empty() {
199 store.refs.keys().cloned().collect()
200 } else {
201 wants
202 .refs
203 .iter()
204 .filter(|n| store.refs.contains_key(*n))
205 .cloned()
206 .collect()
207 };
208 loop {
209 let mut added = Vec::new();
210 for name in &names {
211 if let Some(key) = store.refs.get(name) {
212 if let Some(object) = store.objects.get(&("views".into(), key.clone())) {
213 if let Some(parent) =
214 ViewSnapshot::from_bytes(&object.bytes).and_then(|s| s.parent_view)
215 {
216 if !names.contains(&parent) && store.refs.contains_key(&parent) {
217 added.push(parent);
218 }
219 }
220 }
221 }
222 }
223 if added.is_empty() {
224 break;
225 }
226 names.extend(added);
227 }
228 // Generous fixture inventory: full pulls receive every previously uploaded
229 // non-have object. This isn't a production view authorization policy.
230 let objects = store
231 .objects
232 .values()
233 .filter(|o| {
234 if wants.refs_only {
235 o.family == ObjectFamily::View
236 } else {
237 o.family == ObjectFamily::View || !wants.haves.contains(&o.key)
238 }
239 })
240 .cloned()
241 .collect();
242 let refs = names
243 .into_iter()
244 .filter_map(|name| {
245 store.refs.get(&name).map(|key| RefRecord {
246 name: name.clone(),

Callers

nothing calls this directly

Calls 15

supportedFunction · 0.85
replyFunction · 0.85
lockMethod · 0.80
contains_keyMethod · 0.80
extendMethod · 0.80
errorFunction · 0.70
getMethod · 0.65
decodeFunction · 0.50
unwrapMethod · 0.45
is_emptyMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected