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

Method sync_push

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

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