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

Function validate_path_available

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

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

Callers 1

Calls 2

storage_errFunction · 0.85
get_trunk_by_pathMethod · 0.45

Tested by 1