Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 54500810a0 | |||
| c93bf8f1d2 |
@@ -2,6 +2,7 @@ mod utils;
|
|||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fmt::format;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::{fs, io, time};
|
use std::{fs, io, time};
|
||||||
use utils::{Metadata, Zsdiff, get_hash};
|
use utils::{Metadata, Zsdiff, get_hash};
|
||||||
@@ -20,38 +21,26 @@ async fn walk_dir(dir: String) -> HashMap<String, FileInfo> {
|
|||||||
for e in WalkDir::new(&dir) {
|
for e in WalkDir::new(&dir) {
|
||||||
let e = e.unwrap();
|
let e = e.unwrap();
|
||||||
let path = e.path();
|
let path = e.path();
|
||||||
println!(
|
|
||||||
"Path: {}, {}",
|
|
||||||
path.display(),
|
|
||||||
path.display().to_string().eq(&dir)
|
|
||||||
);
|
|
||||||
if path.display().to_string().eq(&dir) {
|
if path.display().to_string().eq(&dir) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
let content: Vec<u8>;
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
let path_str = path.display().to_string();
|
let path_str = path.display().to_string();
|
||||||
let hash = get_hash(path_str.clone().into_bytes()).await;
|
content = path_str.into_bytes();
|
||||||
let file_info = FileInfo {
|
|
||||||
relative_path: path_str[dir.len() + 1..].to_string(),
|
|
||||||
path: path_str,
|
|
||||||
hash: hash.clone(),
|
|
||||||
is_dir: true,
|
|
||||||
};
|
|
||||||
hash_list.entry(hash).or_insert(file_info);
|
|
||||||
} else {
|
} else {
|
||||||
let content = fs::read(path).unwrap();
|
content = fs::read(path).unwrap();
|
||||||
|
}
|
||||||
let hash = get_hash(content).await;
|
let hash = get_hash(content).await;
|
||||||
let path_str = path.display().to_string();
|
let path_str = path.display().to_string();
|
||||||
let file_info = FileInfo {
|
let file_info = FileInfo {
|
||||||
relative_path: path_str[dir.len() + 1..].to_string(),
|
relative_path: path_str[dir.len() + 1..].to_string(),
|
||||||
path: path_str,
|
path: path_str,
|
||||||
hash: hash.clone(),
|
hash: hash.clone(),
|
||||||
is_dir: false,
|
is_dir: path.is_dir(),
|
||||||
};
|
};
|
||||||
hash_list.entry(hash).or_insert(file_info);
|
hash_list.entry(hash).or_insert(file_info);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
println!("{:?}", hash_list);
|
|
||||||
hash_list
|
hash_list
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +66,6 @@ async fn compare_hashes(old: HashMap<String, FileInfo>, new: HashMap<String, Fil
|
|||||||
}
|
}
|
||||||
|
|
||||||
if new_fileinfo.is_dir {
|
if new_fileinfo.is_dir {
|
||||||
println!("{}", new_fileinfo.is_dir);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +109,7 @@ pub async fn zsdiff(
|
|||||||
utils::compress_parts(parts, &fs::File::create(output_filename)?, level).await;
|
utils::compress_parts(parts, &fs::File::create(output_filename)?, level).await;
|
||||||
let output_data = fs::read(output_filename)?;
|
let output_data = fs::read(output_filename)?;
|
||||||
let size_after = output_data.len();
|
let size_after = output_data.len();
|
||||||
let output_hash = get_hash(output_data).await;
|
let output_hash = format!("{} {}", get_hash(output_data).await, output_filename);
|
||||||
fs::File::create(format!("{}.md5", output_filename))?.write_all(output_hash.as_bytes())?;
|
fs::File::create(format!("{}.md5", output_filename))?.write_all(output_hash.as_bytes())?;
|
||||||
let elapsed = now.elapsed();
|
let elapsed = now.elapsed();
|
||||||
println!("Zsdiff hash: {}", output_hash);
|
println!("Zsdiff hash: {}", output_hash);
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ async fn extract_files(zsdiff: &Zsdiff, filename: String) -> Result<String, io::
|
|||||||
|
|
||||||
async fn check_hash(filename: String) -> Result<(), io::Error> {
|
async fn check_hash(filename: String) -> Result<(), io::Error> {
|
||||||
let file_data = read(format!("{}.zdiff", filename))?;
|
let file_data = read(format!("{}.zdiff", filename))?;
|
||||||
let hash_file = read(format!("{}.zdiff.md5", filename))?;
|
let hash_file = String::from_utf8(read(format!("{}.zdiff.md5", filename))?).unwrap();
|
||||||
let hash = utils::get_hash(file_data).await;
|
let hash = utils::get_hash(file_data).await;
|
||||||
if !String::from_utf8(hash_file).unwrap().eq(&hash) {
|
if !hash_file.split(" ").next().unwrap().eq(&hash) {
|
||||||
return Err(io::Error::new(io::ErrorKind::Other, "Hash mismatch"));
|
return Err(io::Error::new(io::ErrorKind::Other, "Hash mismatch"));
|
||||||
}
|
}
|
||||||
println!("Zsdiff hash: {}", hash);
|
println!("Zsdiff hash: {}", hash);
|
||||||
|
|||||||
Reference in New Issue
Block a user