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

Function apply_undelete

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

Applies an Undelete operation to restore a deleted file. # Behavior 1. Verifies the trunk exists 2. Verifies the trunk is currently deleted 3. Updates the trunk's state to Alive # Errors - `TrunkNotFound` - The trunk doesn't exist - `InvalidTrunkState` - The trunk is not deleted

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

Source from the content-addressed store, hash-verified

256/// - `TrunkNotFound` - The trunk doesn't exist
257/// - `InvalidTrunkState` - The trunk is not deleted
258fn apply_undelete<T: MutCrdtTxnT>(
259 txn: &mut T,
260 context: &mut ApplyContext,
261 trunk_id: TrunkId,
262) -> ApplyResult<()> {
263 // Verify trunk exists
264 let trunk = txn
265 .get_trunk(trunk_id)
266 .map_err(|e| storage_err(e, "getting trunk"))?
267 .ok_or_else(|| ApplyError::trunk_not_found(trunk_id))?;
268
269 // Check current state
270 if !trunk.state().is_deleted() {
271 if context.options().allow_duplicate_ids() {
272 context.record_skipped();
273 return Ok(());
274 }
275 return Err(ApplyError::invalid_trunk_state(
276 trunk_id, "alive", "undelete",
277 ));
278 }
279
280 // Update state to alive
281 txn.update_trunk_state(trunk_id, TrunkState::Alive)
282 .map_err(|e| storage_err(e, "updating trunk state"))?;
283
284 context.record_trunk_undeleted();
285 Ok(())
286}
287
288// Validation Helpers
289

Callers 1

apply_trunk_opFunction · 0.85

Calls 9

storage_errFunction · 0.85
allow_duplicate_idsMethod · 0.80
get_trunkMethod · 0.45
is_deletedMethod · 0.45
stateMethod · 0.45
optionsMethod · 0.45
record_skippedMethod · 0.45
update_trunk_stateMethod · 0.45

Tested by

no test coverage detected