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

Method upload_change

atomic-remote/src/http/upload.rs:25–66  ·  view source on GitHub ↗

Upload a change file. # Arguments `hash` - The base32-encoded hash of the change. `view` - The target view name. `data` - The raw change file data.

(&self, hash: &str, view: &str, data: Bytes)

Source from the content-addressed store, hash-verified

23 /// * `view` - The target view name.
24 /// * `data` - The raw change file data.
25 pub async fn upload_change(&self, hash: &str, view: &str, data: Bytes) -> RemoteResult<()> {
26 let url = format!("{}?insert={}&view={}", self.base_url, hash, view);
27 debug!("POST insert: {} ({} bytes)", url, data.len());
28
29 let response = self
30 .client
31 .post(&url)
32 .header(CONTENT_TYPE, "application/octet-stream")
33 .body(data)
34 .send()
35 .await
36 .map_err(|e| RemoteError::connection_failed(&url, e))?;
37
38 crate::check_min_version_header(response.headers());
39 let status = response.status();
40
41 match status {
42 StatusCode::OK => {
43 debug!("Successfully uploaded change {}", hash);
44 Ok(())
45 }
46 StatusCode::NOT_FOUND => Err(RemoteError::repo_not_found(&url)),
47 StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => {
48 let msg = response.text().await.unwrap_or_default();
49 Err(RemoteError::auth_failed(&url, msg))
50 }
51 StatusCode::BAD_REQUEST | StatusCode::INTERNAL_SERVER_ERROR => {
52 let msg = response.text().await.unwrap_or_default();
53 // Check if it's a missing dependencies error
54 if msg.contains("missing") && msg.contains("dependenc") {
55 // Try to extract hash list from error message
56 Err(RemoteError::missing_deps(vec![]))
57 } else {
58 Err(RemoteError::http(status.as_u16(), msg))
59 }
60 }
61 _ => {
62 let msg = response.text().await.unwrap_or_default();
63 Err(RemoteError::http(status.as_u16(), msg))
64 }
65 }
66 }
67
68 /// Upload a tag (short format).
69 ///

Callers 1

upload_change_smartFunction · 0.80

Calls 6

check_min_version_headerFunction · 0.85
postMethod · 0.80
textMethod · 0.80
headerMethod · 0.45
statusMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected