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