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