Retrieve exact recorded patch data using only a canonical full-hash change IRI (`urn:atomic:change:blake3-256:<52 uppercase Base32 characters>`). Hash prefixes, raw hashes, other resource kinds and noncanonical spellings are errors. Missing objects and oversized encoded objects have explicit statuses; corruption and I/O errors fail closed. No view or working-copy state is consulted, and no KG nod
(
&self,
change_iri: &str,
limits: PatchEvidenceLimits,
)
| 115 | /// GraphOps consume the shared operation budget first, then FileOps. Result |
| 116 | /// limits bound returned data, not the existing decoder's memory usage. |
| 117 | pub fn patch_evidence( |
| 118 | &self, |
| 119 | change_iri: &str, |
| 120 | limits: PatchEvidenceLimits, |
| 121 | ) -> Result<PatchEvidence, RepositoryError> { |
| 122 | limits.validate()?; |
| 123 | let hash = iri::parse_change(change_iri) |
| 124 | .map_err(|error| RepositoryError::Serialization(error.to_string()))?; |
| 125 | let mut result = PatchEvidence { |
| 126 | change_iri: iri::mint_change(&hash), |
| 127 | status: PatchEvidenceStatus::Missing, |
| 128 | graph_ops: None, |
| 129 | file_ops: None, |
| 130 | content_blob: None, |
| 131 | removed_preimage: RemovedPreimageStatus::Unsupported, |
| 132 | }; |
| 133 | let metadata = match std::fs::metadata(self.change_store().change_path(&hash)) { |
| 134 | Ok(metadata) => metadata, |
| 135 | Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(result), |
| 136 | Err(error) => return Err(error.into()), |
| 137 | }; |
| 138 | if metadata.len() > MAX_EVIDENCE_OBJECT_BYTES { |
| 139 | result.status = PatchEvidenceStatus::Unsupported; |
| 140 | return Ok(result); |
| 141 | } |
| 142 | let change = match self.load_change(&hash) { |
| 143 | Ok(change) => change, |
| 144 | Err(RepositoryError::ChangeNotFound { .. }) => return Ok(result), |
| 145 | Err(error) => return Err(error), |
| 146 | }; |
| 147 | if Hash::of(&change.contents) != change.hashed.contents_hash { |
| 148 | return Err(RepositoryError::Serialization( |
| 149 | "patch evidence content-blob hash mismatch".into(), |
| 150 | )); |
| 151 | } |
| 152 | let mut count = limits.max_operations; |
| 153 | let mut bytes = limits.max_operation_bytes; |
| 154 | result.graph_ops = Some(bounded_operations( |
| 155 | &change.hashed.hunks, |
| 156 | &mut count, |
| 157 | &mut bytes, |
| 158 | )?); |
| 159 | result.file_ops = Some(bounded_operations( |
| 160 | change.file_ops(), |
| 161 | &mut count, |
| 162 | &mut bytes, |
| 163 | )?); |
| 164 | result.content_blob = Some(RecordedContentBlob { |
| 165 | hash: change.hashed.contents_hash.to_base32(), |
| 166 | bytes: change |
| 167 | .contents |
| 168 | .iter() |
| 169 | .take(limits.max_content_bytes) |
| 170 | .copied() |
| 171 | .collect(), |
| 172 | total_bytes: change.contents.len(), |
| 173 | truncated: change.contents.len() > limits.max_content_bytes, |
| 174 | }); |