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

Function update_trunk_path

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

Update a trunk's path.

(
    txn: &mut T,
    trunk_id: TrunkId,
    new_path: &str,
)

Source from the content-addressed store, hash-verified

1040
1041/// Update a trunk's path.
1042fn update_trunk_path<T: MutTxnT>(
1043 txn: &mut T,
1044 trunk_id: TrunkId,
1045 new_path: &str,
1046) -> PristineResult<()> {
1047 let key = encode_trunk_id(&trunk_id);
1048
1049 // Get existing trunk
1050 if let Some(mut serialized) = txn.get_crdt_trunk(&key)? {
1051 // Another identity may now occupy the old path in the ambient index.
1052 // Moving this trunk must not remove that other candidate's binding.
1053 if txn.get_trunk_by_path(&serialized.path)? == Some(trunk_id) {
1054 txn.del_crdt_path_trunk(&serialized.path)?;
1055 }
1056
1057 // Update path
1058 serialized.path = new_path.to_string();
1059
1060 // Re-encode and store
1061 let value = encode_trunk_value(&serialized);
1062 txn.put_crdt_trunk(&key, &value)?;
1063
1064 // Add new path index
1065 txn.put_crdt_path_trunk(new_path, &key)?;
1066 }
1067
1068 Ok(())
1069}
1070
1071/// Store a branch in the CRDT tables.
1072fn put_branch<T: MutTxnT>(

Calls 7

encode_trunk_idFunction · 0.85
encode_trunk_valueFunction · 0.85
del_crdt_path_trunkMethod · 0.80
put_crdt_trunkMethod · 0.80
put_crdt_path_trunkMethod · 0.80
get_crdt_trunkMethod · 0.45
get_trunk_by_pathMethod · 0.45