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

Function apply_move

atomic-core/src/crdt/apply/trunk.rs:213–249  ·  view source on GitHub ↗

Applies a Move operation to rename or relocate a file. # Behavior 1. Verifies the trunk exists 2. Verifies the trunk is alive (not deleted) 3. Checks the new path isn't already taken 4. Updates the trunk's path 5. Updates the PATH_TRUNK index # Errors - `TrunkNotFound` - The trunk doesn't exist - `InvalidTrunkState` - The trunk is deleted - `PathAlreadyExists` - The new path is occupied

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

Source from the content-addressed store, hash-verified

211/// - `InvalidTrunkState` - The trunk is deleted
212/// - `PathAlreadyExists` - The new path is occupied
213fn apply_move<T: MutCrdtTxnT>(
214 txn: &mut T,
215 context: &mut ApplyContext,
216 trunk_id: TrunkId,
217 new_path: &str,
218) -> ApplyResult<()> {
219 // Verify trunk exists
220 let trunk = txn
221 .get_trunk(trunk_id)
222 .map_err(|e| storage_err(e, "getting trunk"))?
223 .ok_or_else(|| ApplyError::trunk_not_found(trunk_id))?;
224
225 // Check current state
226 if trunk.state().is_deleted() {
227 return Err(ApplyError::invalid_trunk_state(trunk_id, "deleted", "move"));
228 }
229
230 // Check for path collision (unless it's the same trunk)
231 if let Some(existing) = txn
232 .get_trunk_by_path(new_path)
233 .map_err(|e| storage_err(e, "checking path exists"))?
234 {
235 if existing != trunk_id {
236 return Err(ApplyError::path_already_exists(new_path, existing));
237 }
238 // Moving to same path is a no-op
239 context.record_skipped();
240 return Ok(());
241 }
242
243 // Update path
244 txn.update_trunk_path(trunk_id, new_path)
245 .map_err(|e| storage_err(e, "updating trunk path"))?;
246
247 context.record_trunk_moved();
248 Ok(())
249}
250
251// Undelete Operation
252

Callers 1

apply_trunk_opFunction · 0.85

Calls 8

storage_errFunction · 0.85
record_trunk_movedMethod · 0.80
get_trunkMethod · 0.45
is_deletedMethod · 0.45
stateMethod · 0.45
get_trunk_by_pathMethod · 0.45
record_skippedMethod · 0.45
update_trunk_pathMethod · 0.45

Tested by

no test coverage detected