Skip to main content

safe_remove

Function safe_remove 

Source
pub fn safe_remove<P: AsRef<Path>>(path: P) -> FileSystemResult<()>
Expand description

Removes the specified file or directory safely.

If the path does not exist, this function returns Ok(()) without error. If the path points to a directory, it and all of its contents are removed recursively, equivalent to std::fs::remove_dir_all. If the path points to a file, it is removed with std::fs::remove_file.

§Errors

Returns a [FileSystemError::File] if the removal fails for any reason other than the path not existing (e.g., permission denied, path is in use, etc.).

§Example

use soar_utils::error::FileSystemResult;
use soar_utils::fs::safe_remove;

fn main() -> FileSystemResult<()> {
    safe_remove("/tmp/some_path")?;
    Ok(())
}