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>,
)
| 346 | /// |
| 347 | /// `Ok(())` if the path is available, or an error if it's taken. |
| 348 | pub 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 |