image_optimizer/file_ops/
output_manager.rs

1use anyhow::Result;
2use std::path::{Path, PathBuf};
3
4/// Ensures the output directory structure exists and returns the output file path
5///
6/// # Errors
7/// Returns an error if directory creation fails or path operations are invalid
8pub fn ensure_output_dir(
9    output_path: &Path,
10    input_path: &Path,
11    file_path: &Path,
12) -> Result<PathBuf> {
13    let relative_path = file_path.strip_prefix(input_path)?;
14    let output_file_path = output_path.join(relative_path);
15
16    if let Some(parent) = output_file_path.parent() {
17        std::fs::create_dir_all(parent)?;
18    }
19
20    Ok(output_file_path)
21}