Update a trunk's path.
(
txn: &mut T,
trunk_id: TrunkId,
new_path: &str,
)
| 1040 | |
| 1041 | /// Update a trunk's path. |
| 1042 | fn 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. |
| 1072 | fn put_branch<T: MutTxnT>( |