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)
| 332 | /// save_downloaded_change(&repo, &expected_hash, data)?; |
| 333 | /// ``` |
| 334 | pub 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 |
no test coverage detected