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

Function update_leaf_content

atomic-core/src/apply/file_ops.rs:992–1010  ·  view source on GitHub ↗

Update a leaf's content.

(
    txn: &mut T,
    leaf_id: LeafId,
    new_content: &[u8],
)

Source from the content-addressed store, hash-verified

990
991/// Update a leaf's content.
992fn update_leaf_content<T: MutTxnT>(
993 txn: &mut T,
994 leaf_id: LeafId,
995 new_content: &[u8],
996) -> PristineResult<()> {
997 let key = encode_leaf_id(&leaf_id);
998
999 // Get existing leaf
1000 if let Some(mut serialized) = txn.get_crdt_leaf(&key)? {
1001 // Update content range (actual content is in the change's content blob)
1002 serialized.content_end = serialized.content_start + new_content.len() as u32;
1003
1004 // Re-encode and store
1005 let value = encode_leaf_value(&serialized);
1006 txn.put_crdt_leaf(&key, &value)?;
1007 }
1008
1009 Ok(())
1010}
1011
1012// Tests
1013

Callers 1

apply_leaf_opFunction · 0.85

Calls 5

encode_leaf_idFunction · 0.85
encode_leaf_valueFunction · 0.85
put_crdt_leafMethod · 0.80
get_crdt_leafMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected