use crate::error::{Result, RussError};
use std::fs;
use std::path::Path;
pub fn create_directory_safe(path: &Path) -> Result<()> {
if path.exists() {
return Err(RussError::new_project(format!(
"The directory '{}' already exists",
path.to_string_lossy()
)));
}
fs::create_dir(path).map_err(|err| {
RussError::new_project_with_source(
format!("Failed to create directory '{}'", path.to_string_lossy()),
err,
)
})?;
Ok(())
}
pub fn create_file_safe(path: &Path, content: &str) -> Result<()> {
if path.exists() {
return Err(RussError::new_project(format!(
"The file '{}' already exists",
path.to_string_lossy()
)));
}
fs::write(path, content).map_err(|err| {
RussError::new_project_with_source(
format!("Failed to create file '{}'", path.to_string_lossy()),
err,
)
})?;
Ok(())
}