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

Function validate_trunk_state

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

Validates that a trunk exists and is in the expected state. # Arguments `txn` - The transaction `trunk_id` - The trunk to validate `expected_state` - The expected state, or `None` for any state # Returns The trunk if validation passes.

(
    txn: &T,
    trunk_id: TrunkId,
    expected_state: Option<TrunkState>,
)

Source from the content-addressed store, hash-verified

306///
307/// The trunk if validation passes.
308pub fn validate_trunk_state<T: MutCrdtTxnT>(
309 txn: &T,
310 trunk_id: TrunkId,
311 expected_state: Option<TrunkState>,
312) -> ApplyResult<Trunk> {
313 let trunk = txn
314 .get_trunk(trunk_id)
315 .map_err(|e| storage_err(e, "getting trunk"))?
316 .ok_or_else(|| ApplyError::trunk_not_found(trunk_id))?;
317
318 if let Some(expected) = expected_state {
319 let matches = match expected {
320 TrunkState::Alive => trunk.state().is_alive(),
321 TrunkState::Deleted => trunk.state().is_deleted(),
322 TrunkState::Zombie => trunk.state().is_zombie(),
323 };
324
325 if !matches {
326 return Err(ApplyError::invalid_trunk_state(
327 trunk_id,
328 trunk.state().to_string(),
329 format!("expected {}", expected),
330 ));
331 }
332 }
333
334 Ok(trunk)
335}
336
337/// Checks if a path is available (not taken by another file).
338///

Callers 1

Calls 6

storage_errFunction · 0.85
get_trunkMethod · 0.45
is_aliveMethod · 0.45
stateMethod · 0.45
is_deletedMethod · 0.45
is_zombieMethod · 0.45

Tested by 1