2024-03-25 20:49:12 +00:00
|
|
|
use std::process::exit;
|
2024-03-29 04:18:38 +00:00
|
|
|
use std::sync::{Arc, Mutex};
|
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
|
|
|
snapshot: Snapshot,
|
2024-03-18 21:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl CreateMode {
|
2024-03-29 04:18:38 +00:00
|
|
|
pub fn new(snapshot_path: String, root_path: String) -> CreateMode {
|
2024-03-25 16:59:24 +00:00
|
|
|
if snapshot_path.replace("./", "").is_empty() {
|
2024-03-25 20:49:12 +00:00
|
|
|
println!("Specify output file name");
|
|
|
|
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-29 04:18:38 +00:00
|
|
|
|
2024-03-26 17:14:24 +00:00
|
|
|
CreateMode {
|
|
|
|
snapshot_path,
|
|
|
|
root_path,
|
2024-03-29 04:18:38 +00:00
|
|
|
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,
|
|
|
|
},
|
2024-03-26 17:14:24 +00:00
|
|
|
}
|
2024-03-18 21:47:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-29 04:18:38 +00:00
|
|
|
impl CreateMode {
|
|
|
|
pub 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
|
|
|
}
|
|
|
|
}
|