1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use Result;
use OsStr;
use Path;
/// Creates a backup file by copying the original with a .bak extension.
///
/// This function creates a safety backup of the original file before optimization
/// by copying it to a new file with the same name but with `.bak` appended to the extension.
/// For example, `image.jpg` becomes `image.jpg.bak`.
///
/// # Arguments
///
/// * `file_path` - Path to the file to backup
///
/// # Returns
///
/// Returns `Ok(())` on successful backup creation.
///
/// # Errors
///
/// Returns an error if the file copy operation fails due to:
/// - Insufficient disk space
/// - Permission issues
/// - I/O errors during file copying
///
/// # Examples
///
/// ```rust
/// use std::path::Path;
/// use image_optimizer::file_ops::create_backup;
///
/// # fn example() -> anyhow::Result<()> {
/// let file_path = Path::new("image.jpg");
/// create_backup(file_path)?; // Creates image.jpg.bak
/// # Ok(())
/// # }
/// ```