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

Function apply_delete

atomic-core/src/crdt/apply/trunk.rs:159–187  ·  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

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

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