2024-03-18 21:42:04 +00:00
|
|
|
use std::collections::HashMap;
|
2024-03-18 21:51:52 +00:00
|
|
|
use std::env::args;
|
2024-03-25 20:49:12 +00:00
|
|
|
use std::process::exit;
|
2024-03-18 21:42:04 +00:00
|
|
|
use std::sync::{Arc, Mutex};
|
2024-03-18 20:38:10 +00:00
|
|
|
use Fasching::snapshot::Snapshot;
|
2024-03-18 22:28:33 +00:00
|
|
|
use crate::comparemode::CompareMode;
|
2024-03-18 21:51:52 +00:00
|
|
|
use crate::createmode::CreateMode;
|
2024-03-25 20:49:12 +00:00
|
|
|
use crate::print_help;
|
2024-03-18 20:38:10 +00:00
|
|
|
|
2024-03-18 22:28:33 +00:00
|
|
|
pub enum SysCompareMode {
|
2024-03-18 21:46:19 +00:00
|
|
|
Create,
|
|
|
|
Compare
|
2024-03-18 20:38:10 +00:00
|
|
|
}
|
|
|
|
|
2024-03-18 21:36:14 +00:00
|
|
|
pub struct SysCompareApp {
|
2024-03-18 22:28:33 +00:00
|
|
|
mode: SysCompareMode,
|
2024-03-18 21:42:04 +00:00
|
|
|
args: Vec<String>,
|
|
|
|
comparatives: Arc<Mutex<HashMap<String, Snapshot>>>
|
2024-03-18 20:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-18 21:36:14 +00:00
|
|
|
impl SysCompareApp {
|
2024-03-18 22:28:33 +00:00
|
|
|
pub fn new(mode: SysCompareMode, args: Vec<String>) -> SysCompareApp {
|
2024-03-18 21:42:04 +00:00
|
|
|
SysCompareApp { mode, args, comparatives: Arc::new(Mutex::new(HashMap::new())) }
|
2024-03-18 21:36:14 +00:00
|
|
|
}
|
|
|
|
pub fn run(&self) {
|
|
|
|
println!("running");
|
2024-03-18 21:51:52 +00:00
|
|
|
match self.mode {
|
2024-03-18 22:28:33 +00:00
|
|
|
SysCompareMode::Create => {
|
2024-03-25 16:59:24 +00:00
|
|
|
let snapshot_path = match self.args.get(2) {
|
2024-03-25 20:49:12 +00:00
|
|
|
None => {
|
|
|
|
println!("Missing hash dir path as second argument");
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
|
|
|
}
|
2024-03-18 22:28:33 +00:00
|
|
|
Some(r) => {not_empty(r)}
|
2024-03-18 21:51:52 +00:00
|
|
|
};
|
2024-03-25 19:13:01 +00:00
|
|
|
let root_dir = match self.args.get(3) {
|
2024-03-25 20:49:12 +00:00
|
|
|
None => {
|
|
|
|
println!("Missing hash dir path as second argument");
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
|
|
|
}
|
2024-03-25 16:59:24 +00:00
|
|
|
Some(r) => {not_empty(r)}
|
|
|
|
};
|
|
|
|
let mut create = CreateMode::new(self.args.clone(), snapshot_path.clone(), root_dir.clone());
|
2024-03-18 21:51:52 +00:00
|
|
|
create.run()
|
|
|
|
}
|
2024-03-18 22:28:33 +00:00
|
|
|
SysCompareMode::Compare => {
|
|
|
|
let left = match self.args.get(2) {
|
2024-03-25 20:49:12 +00:00
|
|
|
None => {
|
|
|
|
println!("Missing hash dir path as second argument");
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
|
|
|
}
|
2024-03-18 22:28:33 +00:00
|
|
|
Some(r) => {not_empty(r)}
|
|
|
|
};
|
|
|
|
let right = match self.args.get(3) {
|
2024-03-25 20:49:12 +00:00
|
|
|
None => {
|
|
|
|
println!("Missing output path as third argument");
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
|
|
|
}
|
2024-03-18 22:28:33 +00:00
|
|
|
Some(r) => {not_empty(r)}
|
|
|
|
};
|
2024-03-18 22:20:57 +00:00
|
|
|
|
2024-03-18 22:37:17 +00:00
|
|
|
let mut compare = CompareMode::new(self.args.clone(), left, right);
|
2024-03-18 22:31:45 +00:00
|
|
|
compare.run()
|
2024-03-18 22:20:57 +00:00
|
|
|
}
|
2024-03-18 21:51:52 +00:00
|
|
|
}
|
2024-03-18 20:38:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-18 22:28:33 +00:00
|
|
|
fn not_empty(r: &String) -> String {
|
|
|
|
if r.replace("./", "").is_empty() {
|
2024-03-25 20:49:12 +00:00
|
|
|
println!("Specify input file name");
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
2024-03-18 22:28:33 +00:00
|
|
|
} else {
|
|
|
|
r.to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-18 21:36:14 +00:00
|
|
|
impl Default for SysCompareApp {
|
2024-03-18 20:38:10 +00:00
|
|
|
fn default() -> Self {
|
2024-03-18 22:28:33 +00:00
|
|
|
SysCompareApp { mode: SysCompareMode::Create, args: vec![], comparatives: Arc::new(Mutex::new(HashMap::new())) }
|
2024-03-18 20:38:10 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-18 21:36:14 +00:00
|
|
|
|
|
|
|
pub trait Comparer {
|
2024-03-18 22:37:17 +00:00
|
|
|
fn run(&mut self);
|
2024-03-18 21:36:14 +00:00
|
|
|
}
|