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

Function apply_delete

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

Applies a Delete operation to mark a file as deleted. # Behavior 1. Verifies the trunk exists 2. Verifies the trunk is not already deleted 3. Updates the trunk's state to Deleted Note: The trunk entry remains in the database (tombstone). Associated branches and leaves are not automatically deleted. # Errors - `TrunkNotFound` - The trunk doesn't exist - `InvalidTrunkState` - The trunk is alrea

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

Source from the content-addressed store, hash-verified

164/// - `TrunkNotFound` - The trunk doesn't exist
165/// - `InvalidTrunkState` - The trunk is already deleted
166fn apply_delete<T: MutCrdtTxnT>(
167 txn: &mut T,
168 context: &mut ApplyContext,
169 trunk_id: TrunkId,
170) -> ApplyResult<()> {
171 // Verify trunk exists
172 let trunk = txn
173 .get_trunk(trunk_id)
174 .map_err(|e| storage_err(e, "getting trunk"))?
175 .ok_or_else(|| ApplyError::trunk_not_found(trunk_id))?;
176
177 // Check current state
178 if trunk.state().is_deleted() {
179 if context.options().allow_duplicate_ids() {
180 context.record_skipped();
181 return Ok(());
182 }
183 return Err(ApplyError::invalid_trunk_state(
184 trunk_id, "deleted", "delete",
185 ));
186 }
187
188 // Update state to deleted
189 txn.update_trunk_state(trunk_id, TrunkState::Deleted)
190 .map_err(|e| storage_err(e, "updating trunk state"))?;
191
192 context.record_trunk_deleted();
193 Ok(())
194}
195
196// Move Operation
197

Callers 1

apply_trunk_opFunction · 0.70

Calls 9

storage_errFunction · 0.85
allow_duplicate_idsMethod · 0.80
record_trunk_deletedMethod · 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