renaming
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -460,7 +460,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||
|
||||
[[package]]
|
||||
name = "zdiff_all"
|
||||
name = "zsdiff_all"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
|
||||
10
Cargo.toml
10
Cargo.toml
@@ -1,15 +1,15 @@
|
||||
[package]
|
||||
name = "zdiff_all"
|
||||
name = "zsdiff_all"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[[bin]]
|
||||
name = "zdiff"
|
||||
path = "src/zdiff.rs"
|
||||
name = "zsdiff"
|
||||
path = "src/zsdiff.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "zpatch"
|
||||
path = "src/zpatch.rs"
|
||||
name = "zspatch"
|
||||
path = "src/zspatch.rs"
|
||||
|
||||
[dependencies]
|
||||
zstd = { version = "0.13" }
|
||||
|
||||
4
Makefile
4
Makefile
@@ -1,5 +1,5 @@
|
||||
build:
|
||||
cargo build --release --target x86_64-unknown-linux-gnu --package zdiff_all --bin zpatch
|
||||
cargo build --release --target x86_64-unknown-linux-gnu --package zdiff_all --bin zdiff
|
||||
cargo build --release --target x86_64-unknown-linux-gnu --package zsdiff_all --bin zspatch
|
||||
cargo build --release --target x86_64-unknown-linux-gnu --package zsdiff_all --bin zsdiff
|
||||
#cargo build --release --target x86_64-apple-darwin --package zdiff_all --bin zpatch
|
||||
#cargo build --release --target x86_64-pc-windows-gnu --package zdiff_all --bin zpatch
|
||||
@@ -3,12 +3,12 @@ use std::collections::HashMap;
|
||||
use std::{fs, io};
|
||||
use zstd::{Decoder, Encoder};
|
||||
|
||||
pub struct Zdiff {
|
||||
pub struct Zsdiff {
|
||||
pub content: HashMap<String, Vec<u8>>,
|
||||
pub metadata: Metadata,
|
||||
}
|
||||
|
||||
impl Zdiff {
|
||||
impl Zsdiff {
|
||||
pub async fn from_vec(_data: Vec<Vec<u8>>) -> Result<Self, std::io::Error> {
|
||||
let mut content = HashMap::new();
|
||||
for part in _data {
|
||||
@@ -21,7 +21,7 @@ impl Zdiff {
|
||||
let metadata: Metadata = serde_json::from_slice(meta.as_slice())?;
|
||||
content.remove("metadata.json");
|
||||
|
||||
Ok(Zdiff { content, metadata })
|
||||
Ok(Zsdiff { content, metadata })
|
||||
}
|
||||
|
||||
pub async fn to_vec(&self) -> Vec<Vec<u8>> {
|
||||
|
||||
@@ -3,7 +3,7 @@ mod utils;
|
||||
use clap::Parser;
|
||||
use std::collections::HashMap;
|
||||
use std::{fs, io};
|
||||
use utils::{Metadata, Zdiff, get_hash};
|
||||
use utils::{Metadata, Zsdiff, get_hash};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
struct FileInfo {
|
||||
@@ -33,7 +33,7 @@ async fn walk_dir(dir: String) -> HashMap<String, FileInfo> {
|
||||
hash_list
|
||||
}
|
||||
|
||||
async fn compare_hashes(old: HashMap<String, FileInfo>, new: HashMap<String, FileInfo>) -> Zdiff {
|
||||
async fn compare_hashes(old: HashMap<String, FileInfo>, new: HashMap<String, FileInfo>) -> Zsdiff {
|
||||
let mut diff_files: HashMap<String, Vec<u8>> = HashMap::new();
|
||||
let mut remove_files: Vec<String> = vec![];
|
||||
let mut hashes: HashMap<String, String> = HashMap::new();
|
||||
@@ -55,7 +55,7 @@ async fn compare_hashes(old: HashMap<String, FileInfo>, new: HashMap<String, Fil
|
||||
}
|
||||
}
|
||||
|
||||
Zdiff {
|
||||
Zsdiff {
|
||||
content: diff_files.clone(),
|
||||
metadata: Metadata {
|
||||
diff_files: diff_files.keys().cloned().collect(),
|
||||
@@ -65,7 +65,7 @@ async fn compare_hashes(old: HashMap<String, FileInfo>, new: HashMap<String, Fil
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn zdiff(
|
||||
pub async fn zsdiff(
|
||||
filename: String,
|
||||
old: String,
|
||||
new: String,
|
||||
@@ -100,6 +100,6 @@ struct Args {
|
||||
#[tokio::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
let args = Args::parse();
|
||||
zdiff(args.filename, args.old, args.new, args.compress_level).await?;
|
||||
zsdiff(args.filename, args.old, args.new, args.compress_level).await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -5,7 +5,7 @@ use std::fs::read;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::{fs, io};
|
||||
use utils::Zdiff;
|
||||
use utils::Zsdiff;
|
||||
|
||||
async fn create_tmp_dir(dir_name: String) -> Result<String, io::Error> {
|
||||
let name = format!("{}.tmp", dir_name);
|
||||
@@ -14,11 +14,11 @@ async fn create_tmp_dir(dir_name: String) -> Result<String, io::Error> {
|
||||
Ok(name)
|
||||
}
|
||||
|
||||
async fn extract_files(zdiff: &Zdiff, filename: &String) -> Result<String, io::Error> {
|
||||
async fn extract_files(zsdiff: &Zsdiff, filename: &String) -> Result<String, io::Error> {
|
||||
let tmp_dir_name = create_tmp_dir(filename.to_string()).await?;
|
||||
let path = Path::new(&tmp_dir_name);
|
||||
fs::remove_dir_all(path).ok();
|
||||
for (f, c) in zdiff.content.iter() {
|
||||
for (f, c) in zsdiff.content.iter() {
|
||||
let filepath = path.join(f);
|
||||
fs::create_dir_all(filepath.parent().unwrap())?;
|
||||
fs::File::create(&filepath)?.write_all(c)?;
|
||||
@@ -29,21 +29,21 @@ async fn extract_files(zdiff: &Zdiff, filename: &String) -> Result<String, io::E
|
||||
async fn zpatch(filename: String, dest_dir: String) -> Result<(), io::Error> {
|
||||
let filename = &format!("{}.zdiff", filename);
|
||||
let parts = utils::decompress_parts(read(filename)?).await?;
|
||||
let zdiff = Zdiff::from_vec(parts).await?;
|
||||
let tmp_dir_name = extract_files(&zdiff, filename).await?;
|
||||
for name in zdiff.content.keys().collect::<Vec<&String>>() {
|
||||
let diff = Zsdiff::from_vec(parts).await?;
|
||||
let tmp_dir_name = extract_files(&diff, filename).await?;
|
||||
for name in diff.content.keys().collect::<Vec<&String>>() {
|
||||
let from_path = Path::new(&tmp_dir_name).join(name);
|
||||
let to_path = Path::new(&dest_dir).join(name);
|
||||
fs::create_dir_all(to_path.parent().unwrap())?;
|
||||
fs::copy(from_path, to_path)?;
|
||||
}
|
||||
|
||||
for file in zdiff.metadata.remove_files {
|
||||
for file in diff.metadata.remove_files {
|
||||
let path = Path::new(&dest_dir).join(file);
|
||||
fs::remove_file(path).ok();
|
||||
}
|
||||
|
||||
for (k, hash) in zdiff.metadata.hashes {
|
||||
for (k, hash) in diff.metadata.hashes {
|
||||
let path = Path::new(&dest_dir).join(k);
|
||||
let content = read(path)?;
|
||||
let fs_hash = utils::get_hash(&content).await;
|
||||
Reference in New Issue
Block a user