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

Function apply_replace

atomic-core/src/crdt/apply/leaf.rs:268–299  ·  view source on GitHub ↗

Applies a Replace operation to change a token's content. # Behavior 1. Verifies the leaf exists 2. Verifies the leaf is alive (not deleted) 3. Updates the leaf's content range to point to new content The leaf's ID is preserved, enabling accurate blame tracking. # Errors - `LeafNotFound` - The leaf doesn't exist - `InvalidLeafState` - The leaf is deleted

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

Source from the content-addressed store, hash-verified

266/// - `LeafNotFound` - The leaf doesn't exist
267/// - `InvalidLeafState` - The leaf is deleted
268fn apply_replace<T: MutCrdtTxnT>(
269 txn: &mut T,
270 context: &mut ApplyContext,
271 leaf_id: LeafId,
272 new_content: &[u8],
273 _content: &[u8],
274) -> ApplyResult<()> {
275 // Verify leaf exists
276 let leaf = txn
277 .get_leaf(leaf_id)
278 .map_err(|e| storage_err(e, "getting leaf"))?
279 .ok_or_else(|| ApplyError::leaf_not_found(leaf_id))?;
280
281 // Check current state
282 if leaf.state().is_deleted() {
283 return Err(ApplyError::invalid_leaf_state(
284 leaf_id, "deleted", "replace",
285 ));
286 }
287
288 // Update content range
289 // In a full implementation, we'd compute the actual offset in the content blob
290 let content_len = new_content.len() as u32;
291 let new_range = 0..content_len;
292
293 txn.update_leaf_content(leaf_id, new_range)
294 .map_err(|e| storage_err(e, "updating leaf content"))?;
295
296 context.record_leaf_replaced();
297 context.record_content_bytes(content_len as u64);
298 Ok(())
299}
300
301// Restore Operation
302

Callers 1

apply_leaf_opFunction · 0.85

Calls 8

storage_errFunction · 0.85
record_leaf_replacedMethod · 0.80
record_content_bytesMethod · 0.80
get_leafMethod · 0.45
is_deletedMethod · 0.45
stateMethod · 0.45
lenMethod · 0.45
update_leaf_contentMethod · 0.45

Tested by

no test coverage detected