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

Method upload_change

atomic-remote/src/http/upload.rs:42–89  ·  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

40 /// * `view` - The target view name.
41 /// * `data` - The raw change file data.
42 pub async fn upload_change(&self, hash: &str, view: &str, data: Bytes) -> RemoteResult<()> {
43 let url = format!("{}?insert={}&view={}", self.base_url, hash, view);
44 debug!("POST insert: {} ({} bytes)", url, data.len());
45
46 let response = self
47 .client
48 .post(&url)
49 .header(CONTENT_TYPE, "application/octet-stream")
50 .body(data)
51 .send()
52 .await
53 .map_err(|e| RemoteError::connection_failed(&url, e))?;
54
55 crate::check_min_version_header(response.headers());
56 let status = response.status();
57
58 match status {
59 StatusCode::OK => {
60 debug!("Successfully uploaded change {}", hash);
61 Ok(())
62 }
63 StatusCode::NOT_FOUND => Err(RemoteError::repo_not_found(&url)),
64 StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => {
65 let msg = response.text().await.unwrap_or_default();
66 Err(RemoteError::auth_failed(&url, msg))
67 }
68 StatusCode::BAD_REQUEST | StatusCode::INTERNAL_SERVER_ERROR => {
69 let msg = response.text().await.unwrap_or_default();
70 // Missing-dependency error: name the offending hashes when the
71 // server included them; otherwise preserve the full message
72 // rather than collapsing it to "0 dependencies".
73 if msg.contains("missing") && msg.contains("dependenc") {
74 let hashes = extract_change_hashes(&msg);
75 if hashes.is_empty() {
76 Err(RemoteError::http(status.as_u16(), msg))
77 } else {
78 Err(RemoteError::missing_deps(hashes))
79 }
80 } else {
81 Err(RemoteError::http(status.as_u16(), msg))
82 }
83 }
84 _ => {
85 let msg = response.text().await.unwrap_or_default();
86 Err(RemoteError::http(status.as_u16(), msg))
87 }
88 }
89 }
90
91 /// Store a change file on the remote without applying it to any view.
92 ///

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected