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

Method save_change_bytes

atomic-repository/src/repository/changes.rs:288–345  ·  view source on GitHub ↗

Save a change using pre-serialized ATOM bytes (hash-stable). This writes the exact bytes to disk after inspecting the explicit ATOM file-header version. Version 1 is legacy; version 2 requires the durable `change-format-vnext` repository capability before persistence. # Arguments `hash` - The content hash (from the original serialization) `change_bytes` - The exact ATOM bytes to write to disk `

(
        &self,
        hash: &Hash,
        change_bytes: &[u8],
        change: &Change,
    )

Source from the content-addressed store, hash-verified

286 /// * `change_bytes` - The exact ATOM bytes to write to disk
287 /// * `change` - The deserialized change used for capability checks
288 pub(crate) fn save_change_bytes(
289 &self,
290 hash: &Hash,
291 change_bytes: &[u8],
292 change: &Change,
293 ) -> Result<Hash, RepositoryError> {
294 let version = atom_change_file_version(change_bytes)?;
295 if change
296 .hashed
297 .span
298 .as_ref()
299 .is_some_and(|p| p.version == atomic_core::change::span_patch::LEGACY_SOURCE_VERSION)
300 {
301 let verified = atomic_core::change::VerifiedChange::from_bytes(change_bytes)
302 .map_err(|e| RepositoryError::Serialization(e.to_string()))?;
303 if verified.hash() != *hash
304 || verified.change().hashed != change.hashed
305 || verified.change().contents != change.contents
306 {
307 return Err(RepositoryError::Serialization(
308 "legacy span bytes differ from supplied identity".into(),
309 ));
310 }
311 self.fence_legacy_span_storage(change)?;
312 }
313 self.require_projected_semantic_storage_capability(change)?;
314 if matches!(
315 version,
316 ATOM_CHANGE_FILE_VERSION_SPAN
317 | ATOM_CHANGE_FILE_VERSION_COMPACT
318 | ATOM_CHANGE_FILE_VERSION_FIELDS
319 ) {
320 let (decoded, actual_hash) =
321 Change::deserialize(&mut std::io::Cursor::new(change_bytes))
322 .map_err(|error| RepositoryError::Serialization(error.to_string()))?;
323 if actual_hash != *hash
324 || decoded.hashed != change.hashed
325 || decoded.contents != change.contents
326 {
327 return Err(RepositoryError::Serialization(
328 "span change bytes do not match the supplied change identity".into(),
329 ));
330 }
331 if decoded.hashed.span.is_some() {
332 self.require_span_storage_capability()?;
333 }
334 }
335 if version == ATOM_CHANGE_FILE_VERSION_V2
336 || version == ATOM_CHANGE_FILE_VERSION_SPAN
337 || version == ATOM_CHANGE_FILE_VERSION_COMPACT
338 || version == ATOM_CHANGE_FILE_VERSION_FIELDS
339 {
340 self.pristine
341 .require_repository_capability(CHANGE_FORMAT_VNEXT_CAPABILITY)
342 .map_err(RepositoryError::from)?;
343 }
344 self.save_change_bytes_after_capability_declaration(hash, change_bytes, change)
345 }

Calls 10

atom_change_file_versionFunction · 0.85
as_refMethod · 0.80
deserializeFunction · 0.70
hashMethod · 0.45
changeMethod · 0.45