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