image_optimizer/file_ops/backup_manager.rs
1use anyhow::Result;
2use std::ffi::OsStr;
3use std::path::Path;
4
5/// Creates a backup file by copying the original with a .bak extension
6///
7/// # Errors
8/// Returns an error if the file copy operation fails
9pub fn create_backup(file_path: &Path) -> Result<()> {
10 let backup_path = file_path.with_extension(format!(
11 "{}.bak",
12 file_path.extension().and_then(OsStr::to_str).unwrap_or("")
13 ));
14 std::fs::copy(file_path, backup_path)?;
15 Ok(())
16}