2024-03-26 17:14:24 +00:00
|
|
|
use crate::print_help;
|
|
|
|
use crate::syscompare::Comparer;
|
2024-03-25 20:49:12 +00:00
|
|
|
use std::process::exit;
|
2024-03-25 19:13:01 +00:00
|
|
|
use Fasching::hasher::HashType;
|
2024-03-18 22:04:24 +00:00
|
|
|
use Fasching::hasher::HashType::BLAKE3;
|
2024-03-18 21:47:21 +00:00
|
|
|
use Fasching::snapshot::Snapshot;
|
2024-03-26 17:14:24 +00:00
|
|
|
use Fasching::{create_snapshot, export_snapshot};
|
2024-03-18 21:47:21 +00:00
|
|
|
|
2024-03-18 21:51:52 +00:00
|
|
|
pub struct CreateMode {
|
2024-03-25 16:59:24 +00:00
|
|
|
snapshot_path: String,
|
|
|
|
root_path: String,
|
2024-03-26 17:14:24 +00:00
|
|
|
#[allow(unused)]
|
2024-03-18 22:04:24 +00:00
|
|
|
args: Vec<String>,
|
2024-03-26 17:14:24 +00:00
|
|
|
snapshot: Snapshot,
|
2024-03-18 21:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl CreateMode {
|
2024-03-25 16:59:24 +00:00
|
|
|
pub fn new(args: Vec<String>, snapshot_path: String, root_path: String) -> CreateMode {
|
|
|
|
if snapshot_path.replace("./", "").is_empty() {
|
2024-03-25 20:49:12 +00:00
|
|
|
println!("Specify output file name");
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
2024-03-18 22:14:05 +00:00
|
|
|
}
|
2024-03-25 19:13:01 +00:00
|
|
|
let bind = root_path.clone();
|
|
|
|
let rp = bind.as_str();
|
2024-03-26 17:14:24 +00:00
|
|
|
CreateMode {
|
|
|
|
args,
|
|
|
|
snapshot_path,
|
|
|
|
root_path,
|
|
|
|
snapshot: create_snapshot(rp, HashType::MD5, vec![]),
|
|
|
|
}
|
2024-03-18 21:47:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Comparer for CreateMode {
|
2024-03-18 22:37:17 +00:00
|
|
|
fn run(&mut self) {
|
2024-03-25 16:59:24 +00:00
|
|
|
let snapshot = create_snapshot(self.root_path.as_str(), BLAKE3, vec![]);
|
2024-03-25 16:36:46 +00:00
|
|
|
self.snapshot = snapshot.clone();
|
2024-03-25 20:51:52 +00:00
|
|
|
if let Ok(e) = snapshot.file_hashes.lock() {
|
|
|
|
println!("Total FileHash Entries {}", e.len());
|
|
|
|
}
|
2024-03-26 17:14:24 +00:00
|
|
|
export_snapshot(self.snapshot.clone(), self.snapshot_path.clone(), true);
|
2024-03-18 21:47:21 +00:00
|
|
|
}
|
|
|
|
}
|