Apply a TrunkOp (file-level operation).
(
txn: &mut T,
_change_id: NodeId,
trunk_id: TrunkId,
path: &str,
trunk_op: &TrunkOp,
stats: &mut ApplyFileOpsStats,
)
| 517 | |
| 518 | /// Apply a TrunkOp (file-level operation). |
| 519 | fn apply_trunk_op<T: MutTxnT>( |
| 520 | txn: &mut T, |
| 521 | _change_id: NodeId, |
| 522 | trunk_id: TrunkId, |
| 523 | path: &str, |
| 524 | trunk_op: &TrunkOp, |
| 525 | stats: &mut ApplyFileOpsStats, |
| 526 | ) -> PristineResult<()> { |
| 527 | match trunk_op { |
| 528 | TrunkOp::Create { encoding, .. } => { |
| 529 | // Use the inode the tree layer has already allocated for this |
| 530 | // path during `write_recorded`'s FileAdd pre-pass. Allocating |
| 531 | // a fresh one here would create a parallel inode for the same |
| 532 | // file: the tree layer would index `path → tree_inode → pos` |
| 533 | // while the CRDT layer would index `crdt_inode → trunk`, and |
| 534 | // a caller asking "what's the CRDT trunk for the inode the |
| 535 | // tree returned for this path" would get nothing — even |
| 536 | // though both rows exist. |
| 537 | // |
| 538 | // Falling back to `alloc_inode` only when the tree has no |
| 539 | // entry preserves the original behaviour for CRDT-only |
| 540 | // callers (no FileAdd hunk). |
| 541 | let inode = match txn.get_inode(path)? { |
| 542 | Some(i) => i, |
| 543 | None => txn.alloc_inode()?, |
| 544 | }; |
| 545 | |
| 546 | // Create the serialized trunk record |
| 547 | let serialized = SerializedTrunk { |
| 548 | inode, |
| 549 | state: TrunkState::Alive, |
| 550 | encoding: encoding_to_u8(encoding.as_ref()), |
| 551 | path: path.to_string(), |
| 552 | }; |
| 553 | |
| 554 | // Store in CRDT tables |
| 555 | put_trunk(txn, trunk_id, &serialized)?; |
| 556 | stats.trunks_created += 1; |
| 557 | } |
| 558 | |
| 559 | TrunkOp::Delete { .. } => { |
| 560 | // Mark trunk as deleted (don't remove - CRDT semantics) |
| 561 | update_trunk_state(txn, trunk_id, TrunkState::Deleted)?; |
| 562 | stats.trunks_deleted += 1; |
| 563 | } |
| 564 | |
| 565 | TrunkOp::Move { new_path, .. } => { |
| 566 | // Update trunk path |
| 567 | update_trunk_path(txn, trunk_id, new_path)?; |
| 568 | stats.trunks_moved += 1; |
| 569 | } |
| 570 | |
| 571 | TrunkOp::Undelete { .. } => { |
| 572 | // Restore trunk to alive state |
| 573 | update_trunk_state(txn, trunk_id, TrunkState::Alive)?; |
| 574 | // Count as created for stats purposes |
| 575 | stats.trunks_created += 1; |
| 576 | } |
no test coverage detected