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

Function save_downloaded_change

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

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

Callers 1

Calls 2

deserializeFunction · 0.50
save_changeMethod · 0.45

Tested by

no test coverage detected