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

Function apply_single_file_ops

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

Apply FileOps for a single file.

(
    txn: &mut T,
    change_id: NodeId,
    ops: &FileOps,
    stats: &mut ApplyFileOpsStats,
    next_leaf_idx: &mut u32,
    created_inodes: &HashMap<String, Inode>,
)

Source from the content-addressed store, hash-verified

596
597/// Apply FileOps for a single file.
598fn apply_single_file_ops<T: MutTxnT>(
599 txn: &mut T,
600 change_id: NodeId,
601 ops: &FileOps,
602 stats: &mut ApplyFileOpsStats,
603 next_leaf_idx: &mut u32,
604 created_inodes: &HashMap<String, Inode>,
605) -> PristineResult<()> {
606 // Resolve the TrunkId placeholder. The recorder stores TrunkIds
607 // with `change_id = NodeId::ROOT` as a placeholder meaning "this
608 // change — fill in the real id at apply time" (same convention as
609 // BranchId, see `apply_line_ops_with_position`). Without this
610 // resolution every file recorded in a single change shares
611 // `TrunkId(ROOT, 0)` in the CRDT tables, so queries like
612 // `get_file_content_via_crdt` return branches from every file
613 // concatenated.
614 let raw_trunk_id = ops.trunk_id();
615 let trunk_id = if raw_trunk_id.change_id().is_root() {
616 TrunkId::new(change_id, raw_trunk_id.file_idx())
617 } else {
618 raw_trunk_id
619 };
620 let path = ops.path();
621
622 // Apply trunk operation if present
623 if let Some(trunk_op) = ops.trunk_op() {
624 apply_trunk_op(txn, trunk_id, path, trunk_op, stats, created_inodes)?;
625 }
626
627 // Apply line operations
628 for line_ops in ops.line_ops() {
629 apply_line_ops_with_position(txn, change_id, trunk_id, line_ops, stats, next_leaf_idx)?;
630 }
631
632 Ok(())
633}
634
635/// Apply a TrunkOp (file-level operation).
636fn apply_trunk_op<T: MutTxnT>(

Callers 1

Calls 9

file_idxMethod · 0.80
apply_trunk_opFunction · 0.70
trunk_idMethod · 0.45
is_rootMethod · 0.45
change_idMethod · 0.45
pathMethod · 0.45
trunk_opMethod · 0.45
line_opsMethod · 0.45

Tested by

no test coverage detected