.
This commit is contained in:
parent
811f1fa30d
commit
4d244af93f
@ -83,13 +83,22 @@ mod tests {
|
||||
use std::fmt::format;
|
||||
use crate::comparemode::CompareMode;
|
||||
use crate::createmode::CreateMode;
|
||||
use crate::syscompare::Comparer;
|
||||
|
||||
#[test]
|
||||
fn compare_mode() {
|
||||
let user = whoami::username();
|
||||
println!("{user}");
|
||||
|
||||
let left = format!("/home/{}/test1", user);
|
||||
println!("{left}");
|
||||
let right = format!("/home/{}/test2", user);
|
||||
let n1 = CreateMode::new(vec![], left.clone(), right.clone());
|
||||
println!("{right}");
|
||||
|
||||
let mut n1 = CreateMode::new(vec![], left.clone());
|
||||
n1.run();
|
||||
let mut n2 = CreateMode::new(vec![], right.clone());
|
||||
n2.run();
|
||||
|
||||
let cm = CompareMode::new(vec![], left.clone(), right.clone());
|
||||
}
|
||||
|
@ -4,26 +4,26 @@ use Fasching::snapshot::Snapshot;
|
||||
use crate::syscompare::Comparer;
|
||||
|
||||
pub struct CreateMode {
|
||||
in_path: String,
|
||||
out_path: String,
|
||||
path: String,
|
||||
args: Vec<String>,
|
||||
snapshot: Snapshot
|
||||
}
|
||||
|
||||
impl CreateMode {
|
||||
pub fn new(args: Vec<String>, in_path: String, out_path: String) -> CreateMode {
|
||||
if out_path.replace("./", "").is_empty() {
|
||||
pub fn new(args: Vec<String>, path: String) -> CreateMode {
|
||||
if path.replace("./", "").is_empty() {
|
||||
panic!("Specify output file name")
|
||||
}
|
||||
|
||||
CreateMode { in_path, out_path, args, snapshot: Default::default() }
|
||||
CreateMode { args, path, snapshot: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Comparer for CreateMode {
|
||||
fn run(&mut self) {
|
||||
let snapshot = create_snapshot(self.in_path.as_str(), BLAKE3);
|
||||
let snapshot = create_snapshot(self.path.as_str(), BLAKE3);
|
||||
self.snapshot = snapshot.clone();
|
||||
println!("Total FileHash Entries {}", snapshot.file_hashes.lock().unwrap().len());
|
||||
let _ = export_snapshot(snapshot, self.out_path.clone());
|
||||
let _ = export_snapshot(self.snapshot.clone(), self.path.clone());
|
||||
}
|
||||
}
|
||||
|
@ -25,15 +25,11 @@ impl SysCompareApp {
|
||||
println!("running");
|
||||
match self.mode {
|
||||
SysCompareMode::Create => {
|
||||
let in_path = match self.args.get(2) {
|
||||
let path = match self.args.get(2) {
|
||||
None => {panic!("Missing hash dir path as second argument")}
|
||||
Some(r) => {not_empty(r)}
|
||||
};
|
||||
let out_path = match self.args.get(3) {
|
||||
None => {panic!("Missing output path as third argument")}
|
||||
Some(r) => {not_empty(r)}
|
||||
};
|
||||
let mut create = CreateMode::new(self.args.clone(), in_path.clone(), out_path.clone());
|
||||
let mut create = CreateMode::new(self.args.clone(), path.clone());
|
||||
create.run()
|
||||
}
|
||||
SysCompareMode::Compare => {
|
||||
|
Loading…
Reference in New Issue
Block a user