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

Method sync_pull

atomic-remote/src/http/code_sync.rs:79–119  ·  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

77 /// missing objects + current ref targets. An empty [`SyncWants::refs`] asks
78 /// for every view (a full clone).
79 pub async fn sync_pull(&self, wants: &SyncWants) -> RemoteResult<SyncPack> {
80 let url = self.base_url.as_str().to_string();
81 let body = wants
82 .encode()
83 .map_err(|e| RemoteError::protocol(format!("failed to encode sync wants: {e}")))?;
84 let response = self
85 .client
86 .get(&url)
87 .header(PROTOCOL_HEADER, PROTOCOL_SYNC_V1)
88 .header(CONTENT_TYPE, SYNC_MEDIA_TYPE)
89 .body(body)
90 .send()
91 .await
92 .map_err(|e| RemoteError::connection_failed(&url, e))?;
93 crate::check_min_version_header(response.headers());
94 // Capture the server's reported min-version before consuming the body,
95 // so we can include it in a version-mismatch error if decode fails.
96 let server_version = crate::read_min_version_header(response.headers());
97 match response.status() {
98 StatusCode::OK => {
99 let bytes = response
100 .bytes()
101 .await
102 .map_err(|e| RemoteError::connection_failed(&url, e))?;
103 SyncPack::decode(&bytes).map_err(|e| match e {
104 SyncError::Compression(_) | SyncError::Codec(_) => {
105 RemoteError::version_mismatch(crate::VERSION, server_version, e.to_string())
106 }
107 _ => RemoteError::protocol(format!("failed to decode sync pack: {e}")),
108 })
109 }
110 StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => Err(RemoteError::auth_failed(
111 &url,
112 response.text().await.unwrap_or_default(),
113 )),
114 s => Err(RemoteError::http(
115 s.as_u16(),
116 response.text().await.unwrap_or_default(),
117 )),
118 }
119 }
120}

Callers 4

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

Calls 9

check_min_version_headerFunction · 0.85
read_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