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

Function save_downloaded_change

atomic-cli/src/commands/pull/helpers.rs:197–217  ·  view source on GitHub ↗

Save a downloaded change to the repository's change store. Writes the change data to the appropriate location in the repository's `.atomic/changes/` directory structure. # Arguments `repo` - The repository to save to `hash` - The expected hash of the change (for verification) `data` - The raw change file data # Returns `Ok(())` on success, or an appropriate error. # Errors - `CliError::Inte

(repo: &Repository, hash: &Hash, data: Bytes)

Source from the content-addressed store, hash-verified

195/// save_downloaded_change(&repo, &expected_hash, data)?;
196/// ```
197pub fn save_downloaded_change(repo: &Repository, hash: &Hash, data: Bytes) -> CliResult<()> {
198 // Deserialize the change from bytes
199 let mut cursor = Cursor::new(&data[..]);
200 let (change, computed_hash) = Change::deserialize(&mut cursor)
201 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to deserialize change: {}", e)))?;
202
203 // Verify the hash matches what we expected
204 if computed_hash != *hash {
205 return Err(CliError::Internal(anyhow::anyhow!(
206 "Hash mismatch: expected {}, got {}",
207 hash.to_base32(),
208 computed_hash.to_base32()
209 )));
210 }
211
212 // Save to the change store
213 repo.save_change(&change)
214 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to save change: {}", e)))?;
215
216 Ok(())
217}
218
219// Error Conversion
220

Callers 1

run_asyncMethod · 0.70

Calls 2

deserializeFunction · 0.85
save_changeMethod · 0.45

Tested by

no test coverage detected