Skip to main content

create_directories

Function create_directories 

Source
pub fn create_directories(paths: &Paths) -> Result<()>
Expand description

Creates and verifies required directories for site generation.

Ensures all necessary directories exist and are safe to use, creating them if necessary. Also performs security checks on each directory.

§Arguments

  • paths - Reference to a Paths struct containing required directory paths

§Returns

  • Ok(()) - If all directories are created/verified successfully
  • Err - If any directory operation fails

§Examples

use std::path::PathBuf;
use ssg::{Paths, create_directories};

fn main() -> anyhow::Result<()> {
    let paths = Paths {
        site: PathBuf::from("public"),
        content: PathBuf::from("content"),
        build: PathBuf::from("build"),
        template: PathBuf::from("templates"),
    };

    create_directories(&paths)?;
    println!("All directories ready");
    Ok(())
}

§Security

Performs the following security checks:

  • Path traversal prevention
  • Permission validation
  • Safe path verification