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

Function update_leaf_content

atomic-core/src/apply/file_ops.rs:1152–1170  ·  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

1150
1151/// Update a leaf's content.
1152fn update_leaf_content<T: MutTxnT>(
1153 txn: &mut T,
1154 leaf_id: LeafId,
1155 new_content: &[u8],
1156) -> PristineResult<()> {
1157 let key = encode_leaf_id(&leaf_id);
1158
1159 // Get existing leaf
1160 if let Some(mut serialized) = txn.get_crdt_leaf(&key)? {
1161 // Update content range (actual content is in the change's content blob)
1162 serialized.content_end = serialized.content_start + new_content.len() as u32;
1163
1164 // Re-encode and store
1165 let value = encode_leaf_value(&serialized);
1166 txn.put_crdt_leaf(&key, &value)?;
1167 }
1168
1169 Ok(())
1170}
1171
1172// Tests
1173

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