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

Method sync_push

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

Push a [`SyncPack`] to the remote's `/code` endpoint. A `409 Conflict` (a divergent, non-fast-forward ref move) surfaces as a [`RemoteError::ProtocolError`] carrying the server's message, so the caller can tell the user to pull first.

(&self, pack: &SyncPack)

Source from the content-addressed store, hash-verified

40 /// [`RemoteError::ProtocolError`] carrying the server's message, so the caller
41 /// can tell the user to pull first.
42 pub async fn sync_push(&self, pack: &SyncPack) -> RemoteResult<PushSummary> {
43 let url = self.base_url.as_str().to_string();
44 let body = pack
45 .encode()
46 .map_err(|e| RemoteError::protocol(format!("failed to encode sync pack: {e}")))?;
47 let response = self
48 .client
49 .post(&url)
50 .header(PROTOCOL_HEADER, PROTOCOL_SYNC_V1)
51 .header(CONTENT_TYPE, SYNC_MEDIA_TYPE)
52 .body(body)
53 .send()
54 .await
55 .map_err(|e| RemoteError::connection_failed(&url, e))?;
56 crate::check_min_version_header(response.headers());
57 match response.status() {
58 StatusCode::OK | StatusCode::CREATED => {
59 Ok(response.json::<PushSummary>().await.unwrap_or_default())
60 }
61 StatusCode::CONFLICT => Err(RemoteError::protocol(
62 response.text().await.unwrap_or_default(),
63 )),
64 StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => Err(RemoteError::auth_failed(
65 &url,
66 response.text().await.unwrap_or_default(),
67 )),
68 s => Err(RemoteError::http(
69 s.as_u16(),
70 response.text().await.unwrap_or_default(),
71 )),
72 }
73 }
74
75 /// Pull from the remote's `/code` endpoint: send `wants` (which views, and
76 /// the object keys already held) and decode the returned [`SyncPack`] of

Callers 1

run_asyncMethod · 0.80

Calls 7

check_min_version_headerFunction · 0.85
postMethod · 0.80
textMethod · 0.80
as_strMethod · 0.45
encodeMethod · 0.45
headerMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected