ensure_dir

Function ensure_dir 

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

Ensures a directory exists, creating it and all parent directories if necessary.

This function is cross-platform and handles:

  • Windows long paths (>260 characters) automatically
  • Permission errors with helpful error messages
  • Existing files at the target path (returns error)

§Arguments

  • path - The directory path to create

§Returns

  • Ok(()) if the directory exists or was successfully created
  • Err if the path exists but is not a directory, or creation fails

§Examples

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

// Create nested directories
ensure_dir(Path::new("output/agents/subdir"))?;

§Platform Notes

  • Windows: Automatically handles long paths and provides specific error guidance
  • Unix: Respects umask for directory permissions
  • All platforms: Creates parent directories recursively