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

Function save_downloaded_change

atomic-cli/src/commands/clone/helpers.rs:334–354  ·  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

332/// save_downloaded_change(&repo, &expected_hash, data)?;
333/// ```
334pub fn save_downloaded_change(repo: &Repository, hash: &Hash, data: Bytes) -> CliResult<()> {
335 // Deserialize the change from bytes
336 let mut cursor = Cursor::new(&data[..]);
337 let (change, computed_hash) = Change::deserialize(&mut cursor)
338 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to deserialize change: {}", e)))?;
339
340 // Verify the hash matches what we expected
341 if computed_hash != *hash {
342 return Err(CliError::Internal(anyhow::anyhow!(
343 "Hash mismatch: expected {}, got {}",
344 hash.to_base32(),
345 computed_hash.to_base32()
346 )));
347 }
348
349 // Save to the change store
350 repo.save_change(&change)
351 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to save change: {}", e)))?;
352
353 Ok(())
354}
355
356// Error Conversion
357

Callers 1

run_asyncMethod · 0.70

Calls 2

deserializeFunction · 0.85
save_changeMethod · 0.45

Tested by

no test coverage detected