sys-compare/src/createmode.rs
jkoonts caf9f5140b .
2024-03-29 00:21:51 -04:00

47 lines
1.3 KiB
Rust

use std::process::exit;
use std::sync::{Arc, Mutex};
use Fasching::hasher::HashType::BLAKE3;
use Fasching::snapshot::Snapshot;
use Fasching::{create_snapshot, export_snapshot};
pub struct CreateMode {
snapshot_path: String,
root_path: String,
snapshot: Snapshot,
}
impl CreateMode {
pub fn new(snapshot_path: String, root_path: String) -> CreateMode {
if snapshot_path.replace("./", "").is_empty() {
println!("Specify output file name");
exit(0);
}
let bind = root_path.clone();
let rp = bind.as_str();
CreateMode {
snapshot_path,
root_path,
snapshot: Snapshot {
file_hashes: Arc::new(Mutex::new(Default::default())),
black_list: vec![],
root_path: "".to_string(),
hash_type: BLAKE3,
uuid: "".to_string(),
date_created: 0,
},
}
}
}
impl CreateMode {
pub fn run(&mut self) {
let snapshot = create_snapshot(self.root_path.as_str(), BLAKE3, vec![]);
self.snapshot = snapshot.clone();
if let Ok(e) = snapshot.file_hashes.lock() {
println!("Total FileHash Entries {}", e.len());
}
export_snapshot(self.snapshot.clone(), self.snapshot_path.clone(), true);
}
}