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

Function validate_path_available

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

Checks if a path is available (not taken by another file). # Arguments `txn` - The transaction `path` - The path to check `exclude` - Optionally exclude this trunk from the check # Returns `Ok(())` if the path is available, or an error if it's taken.

(
    txn: &T,
    path: &str,
    exclude: Option<TrunkId>,
)

Source from the content-addressed store, hash-verified

346///
347/// `Ok(())` if the path is available, or an error if it's taken.
348pub fn validate_path_available<T: MutCrdtTxnT>(
349 txn: &T,
350 path: &str,
351 exclude: Option<TrunkId>,
352) -> ApplyResult<()> {
353 if let Some(existing) = txn
354 .get_trunk_by_path(path)
355 .map_err(|e| storage_err(e, "checking path"))?
356 {
357 if exclude != Some(existing) {
358 return Err(ApplyError::path_already_exists(path, existing));
359 }
360 }
361 Ok(())
362}
363
364// Tests
365

Callers 1

Calls 2

storage_errFunction · 0.85
get_trunk_by_pathMethod · 0.45

Tested by 1