remove_dir_all

Function remove_dir_all 

Source
pub fn remove_dir_all(path: &Path) -> Result<()>
Expand description

Recursively removes a directory and all its contents.

This function safely removes a directory tree, handling the case where the directory doesn’t exist (no error). It’s designed to be safe for cleanup operations where the directory may or may not exist.

§Arguments

  • path - The directory to remove

§Returns

  • Ok(()) if the directory was removed or didn’t exist
  • Err if the removal failed due to permissions or other filesystem errors

§Examples

use agpm_cli::utils::fs::remove_dir_all;
use std::path::Path;

// Safe cleanup - won't error if directory doesn't exist
remove_dir_all(Path::new("temp/cache"))?;

§Safety

  • Does not follow symbolic links outside the directory tree
  • Handles permission errors with descriptive messages
  • Safe to call on non-existent directories

§Platform Notes

  • Windows: Handles long paths and readonly files
  • Unix: Respects file permissions
  • All platforms: Atomic operation where supported by filesystem