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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Utility for safely appending to text files.
//!
//! This module allows you to add a line to the end of a file, including
//! duplicate checking and optional backup creation.
/**
* add_line_file.rs
*
* (C) Copyright 2026 AtlantisOS Project
* by @NachtsternBuild
*
* License: GNU GENERAL PUBLIC LICENSE Version 3
*/
use fs;
use ;
use Path;
/// Adds a specific line to the end of a file if it does not yet exist.
///
/// This function is particularly useful for configuration files where
/// entries must not appear more than once.
///
/// # How it works
/// 1. **Existence check:** If the file does not exist, it is created with the line.
/// 2. **Duplicate check:** The file is read. If the line (trimmed) already
/// exists, the operation is aborted to avoid redundancy.
/// 3. **Backup:** If `create_backup` is true, a `.bak` copy is created.
/// 4. **Write:** The line is appended to the file in append mode.
///
/// # Arguments
/// * `create_backup` - Whether to create a backup copy of the original file.
/// * `path` - The path to the destination file.
/// * `line` - The text content to be added.
///
/// # Usage:
///
/// ```rust
/// fn main() {
/// let file_path = "test.txt";
/// let new_line = "Some content";
/// let create_backup = true;
/// match add_line_file(&create_backup, file_path, new_line) {
/// Ok(_) => println!("Success!"),
/// Err(e) => eprintln!("Some errors: {}", e),
/// }
/// }
/// ```