Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mon-ius committed Mar 4, 2024
1 parent e5cac37 commit 585ee7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ato-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ato-cli"
version = "0.1.2"
version = "0.1.3"
edition = "2021"

[dependencies]
Expand Down
44 changes: 25 additions & 19 deletions ato/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
use walkdir::WalkDir;
use std::fs;
use std::path;

pub fn _hash(r: &str, p: &path::Path, e: &str) -> Result<(), Box<dyn std::error::Error>>{
let _dir = p.with_file_name("");
let _num = _dir.file_name().unwrap().to_str().unwrap();
let _in = p.with_file_name(format!("{}_{}_{}", _num, "total", e));
let _up = p.with_file_name(format!("{}_{}_{}", _num, "up", e));
let _low = p.with_file_name(format!("{}_{}_{}", _num, "low", e));
if _in.is_file() && _up.is_file() && _low.is_file() {
let contents = fs::read(&_in).expect("Unable to read the file");
let digest = md5::compute(&contents);
let md5_dir = format!("{}/{:x}", r, digest);

let _ = fs::create_dir_all(&md5_dir)?;
let _ = fs::copy(_in, format!("{}/in.stl", &md5_dir))?;
let _ = fs::copy(_up, format!("{}/up.stl", &md5_dir))?;
let _ = fs::copy(_low, format!("{}/low.stl", &md5_dir))?;
let _ = fs::copy(p, format!("{}/gt.stl", &md5_dir))?;
}
else {
println!("{:#?}", p);
}
Ok(())
}

pub fn process(_pth: &str, _e:&str) -> Result<(), Box<dyn std::error::Error>> {
let _root = format!("{}_sha", _pth.to_owned());
Expand All @@ -8,25 +32,7 @@ pub fn process(_pth: &str, _e:&str) -> Result<(), Box<dyn std::error::Error>> {
for entry in WalkDir::new(_pth).into_iter().filter_map(|e| e.ok()) {
let pth = entry.path();
if pth.display().to_string().contains("gt") {
let _dir = pth.with_file_name("");
let _num = _dir.file_name().unwrap().to_str().unwrap();
let _in = pth.with_file_name(format!("{}_{}_{}", _num, "total", _e));
let _up = pth.with_file_name(format!("{}_{}_{}", _num, "up", _e));
let _low = pth.with_file_name(format!("{}_{}_{}", _num, "low", _e));
if _in.is_file() && _up.is_file() && _low.is_file() {
let contents = fs::read(&_in).expect("Unable to read the file");
let digest = md5::compute(&contents);
let md5_dir = format!("{}/{:x}", _root, digest);
let _ = fs::create_dir_all(&md5_dir)?;
let _ = fs::copy(_in, format!("{}/in.stl", &md5_dir))?;
let _ = fs::copy(_up, format!("{}/up.stl", &md5_dir))?;
let _ = fs::copy(_low, format!("{}/low.stl", &md5_dir))?;
let _ = fs::copy(pth, format!("{}/gt.stl", &md5_dir))?;
}
else {
println!("{:#?}", pth);
}

let _ = _hash(&_root, pth, _e);
}
}
Ok(())
Expand Down

0 comments on commit 585ee7d

Please sign in to comment.