implement daemon mode argument option

This commit is contained in:
postscriptum 2025-07-03 12:53:59 +03:00
parent 77d0650aef
commit 1e3043d683
4 changed files with 58 additions and 21 deletions

View file

@ -18,6 +18,7 @@ pub struct Nex {
attachment: Attachment,
filename: String,
is_cleanup: bool,
is_debug: bool,
pattern: String,
time_format: String,
users: HashMap<String, PathBuf>,
@ -30,7 +31,7 @@ impl Nex {
time_format: String,
pattern: String,
attachment_mode: Option<String>,
is_cleanup: bool,
(is_cleanup, is_debug): (bool, bool),
user_names: &Vec<String>,
) -> Result<Self> {
use std::path::MAIN_SEPARATOR;
@ -55,6 +56,7 @@ impl Nex {
attachment: Attachment::init(attachment_mode)?,
filename,
is_cleanup,
is_debug,
pattern,
time_format,
users,
@ -225,7 +227,9 @@ impl Nex {
}
pub fn clean(&self, name: &str, ignore: HashSet<PathBuf>) -> Result<Clean> {
println!("\t\tcleanup...");
if self.is_debug {
println!("\t\tcleanup...");
}
let mut r = Clean::default();
for entry in
walkdir::WalkDir::new(PathBuf::from(self.users.get(name).unwrap())).follow_links(false)
@ -233,7 +237,9 @@ impl Nex {
let e = entry?;
let p = e.path();
let s = p.to_string_lossy();
println!("\t\tcheck `{s}`...");
if self.is_debug {
println!("\t\tcheck `{s}`...");
}
if ignore.contains(p) {
continue;
}
@ -241,11 +247,15 @@ impl Nex {
if m.is_file() {
fs::remove_file(p)?;
r.files += 1;
println!("\t\t\tdelete file `{s}`");
if self.is_debug {
println!("\t\t\tdelete file `{s}`");
}
} else if m.is_dir() {
fs::remove_dir_all(p)?;
r.directories += 1;
println!("\t\t\tdelete directory `{s}`");
if self.is_debug {
println!("\t\t\tdelete directory `{s}`");
}
} else {
panic!()
}