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

Method sync_pull

atomic-remote/src/http/code_sync.rs:77–110  ·  view source on GitHub ↗

Pull from the remote's `/code` endpoint: send `wants` (which views, and the object keys already held) and decode the returned [`SyncPack`] of missing objects + current ref targets. An empty [`SyncWants::refs`] asks for every view (a full clone).

(&self, wants: &SyncWants)

Source from the content-addressed store, hash-verified

75 /// missing objects + current ref targets. An empty [`SyncWants::refs`] asks
76 /// for every view (a full clone).
77 pub async fn sync_pull(&self, wants: &SyncWants) -> RemoteResult<SyncPack> {
78 let url = self.base_url.as_str().to_string();
79 let body = wants
80 .encode()
81 .map_err(|e| RemoteError::protocol(format!("failed to encode sync wants: {e}")))?;
82 let response = self
83 .client
84 .get(&url)
85 .header(PROTOCOL_HEADER, PROTOCOL_SYNC_V1)
86 .header(CONTENT_TYPE, SYNC_MEDIA_TYPE)
87 .body(body)
88 .send()
89 .await
90 .map_err(|e| RemoteError::connection_failed(&url, e))?;
91 crate::check_min_version_header(response.headers());
92 match response.status() {
93 StatusCode::OK => {
94 let bytes = response
95 .bytes()
96 .await
97 .map_err(|e| RemoteError::connection_failed(&url, e))?;
98 SyncPack::decode(&bytes)
99 .map_err(|e| RemoteError::protocol(format!("failed to decode sync pack: {e}")))
100 }
101 StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => Err(RemoteError::auth_failed(
102 &url,
103 response.text().await.unwrap_or_default(),
104 )),
105 s => Err(RemoteError::http(
106 s.as_u16(),
107 response.text().await.unwrap_or_default(),
108 )),
109 }
110 }
111}

Callers 4

run_asyncMethod · 0.80
hint_other_viewsMethod · 0.80
run_asyncMethod · 0.80
run_asyncMethod · 0.80

Calls 8

check_min_version_headerFunction · 0.85
decodeFunction · 0.85
textMethod · 0.80
getMethod · 0.65
as_strMethod · 0.45
encodeMethod · 0.45
headerMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected