diff --git a/Cargo.lock b/Cargo.lock index 8771f6eb8a777f544ae91ad10eaa5f4eb60b60ae..22e97a6a017e3111aaf8302072b3948286a56bf5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1242,7 +1242,6 @@ dependencies = [ "pkgar-keys", "redoxer", "serde", - "sha2", "termion", "toml 0.5.11", "walkdir", @@ -1571,17 +1570,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha2" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" -dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.10.7", -] - [[package]] name = "sha3" version = "0.8.2" diff --git a/Cargo.toml b/Cargo.toml index 3d33a986ccc096b4fd576e9ee67697a24f3fe487..1ed0450d2c1b6a8d4b7fe27d8ff7ccb19671b15a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ pkgar = "0.1.7" pkgar-keys = "0.1.0" redoxer = "0.2" serde = { version = "1.0.110", features = ["derive"] } -sha2 = "0.10" termion = "1.5.5" toml = "0.5.6" walkdir = "2.3.1" diff --git a/src/bin/cook.rs b/src/bin/cook.rs index 7a2c4edde815513f9e6de2f6c77c54680402cbc0..2c037993ea9fd7a78e9cc53a2d2ce5d8535449b1 100644 --- a/src/bin/cook.rs +++ b/src/bin/cook.rs @@ -1,6 +1,5 @@ use cookbook::blake3::blake3_progress; use cookbook::recipe::{Recipe, SourceRecipe, BuildKind, BuildRecipe, PackageRecipe}; -use cookbook::sha256::sha256_progress; use cookbook::recipe_find::recipe_find; use std::{ env, @@ -250,7 +249,7 @@ fi"#); command.arg("submodule").arg("update").arg("--init").arg("--recursive"); run_command(command)?; }, - Some(SourceRecipe::Tar { tar, blake3, sha256, patches, script }) => { + Some(SourceRecipe::Tar { tar, blake3, patches, script }) => { if ! source_dir.is_dir() { // Download tar //TODO: replace wget @@ -292,26 +291,6 @@ fi"#); ); } - //TODO: if blake3 is set, remove sha256 - if let Some(sha256) = sha256 { - // Calculate sha256 - let source_tar_sha256 = sha256_progress(&source_tar).map_err(|err| format!( - "failed to calculate sha256 of '{}': {}\n{:?}", - source_tar.display(), - err, - err - ))?; - - // Check if it matches recipe - if &source_tar_sha256 != sha256 { - return Err(format!( - "calculated sha256 '{}' does not match recipe sha256 '{}'", - source_tar_sha256, - sha256 - )); - } - } - // Create source.tmp let source_dir_tmp = recipe_dir.join("source.tmp"); create_dir_clean(&source_dir_tmp)?; @@ -430,7 +409,7 @@ fn build(recipe_dir: &Path, source_dir: &Path, target_dir: &Path, build: &BuildR eprintln!("DEBUG: '{}' newer than '{}'", source_dir.display(), stage_dir.display()); remove_all(&stage_dir)?; } - + if ! stage_dir.is_dir() { // Create stage.tmp let stage_dir_tmp = target_dir.join("stage.tmp"); diff --git a/src/lib.rs b/src/lib.rs index 572b1716f87dfa24d4175702651507d0fe4ac17f..29b67806257d90ab5e52a80d9492fa5a0d505b0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ pub mod blake3; pub mod recipe; -pub mod sha256; pub mod recipe_find; mod progress_bar; diff --git a/src/recipe.rs b/src/recipe.rs index fea26680a664cd11d33e3b213dc1f4a87a460b3e..197396c756b9552ff05b8435446cb89f8f24b6b9 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -24,8 +24,6 @@ pub enum SourceRecipe { /// The optional blake3 sum of the tar file. Please specify this to make reproducible /// builds more reliable blake3: Option<String>, - /// The optional sha256 sum of the tar file. This is a slower alternative to a blake3 sum - sha256: Option<String>, /// A list of patch files to apply to the source #[serde(default)] patches: Vec<String>, @@ -118,7 +116,7 @@ mod tests { let recipe: Recipe = toml::from_str(r#" [source] tar = "http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.xz" - sha256 = "4f3fc6178a533d392064f14776b23c397ed4b9f48f5de297aba73b643f955c08" + sha256 = "8220c0e4082fa26c07b10bfe31f641d2e33ebe1d1bb0b20221b7016bc8b78a3a" [build] template = "custom" @@ -128,8 +126,7 @@ mod tests { assert_eq!(recipe, Recipe { source: Some(SourceRecipe::Tar { tar: "http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.xz".to_string(), - blake3: None, - sha256: Some("4f3fc6178a533d392064f14776b23c397ed4b9f48f5de297aba73b643f955c08".to_string()), + blake3: Some("8220c0e4082fa26c07b10bfe31f641d2e33ebe1d1bb0b20221b7016bc8b78a3a".to_string()), patches: Vec::new(), script: None, }), diff --git a/src/sha256.rs b/src/sha256.rs deleted file mode 100644 index 5f85a0d1ba8bd3b875643986c44da5556dd100f2..0000000000000000000000000000000000000000 --- a/src/sha256.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::{ - fs, - io::{Read, Result}, - path::Path, - time::Duration, -}; -use sha2::{Digest, Sha256}; - -use crate::progress_bar::{ProgressBar, ProgressBarRead}; - -pub fn sha256<R: Read>(r: &mut R) -> Result<String> { - let mut hasher = Sha256::default(); - - let mut data = vec![0; 4 * 1024 * 1024]; - loop { - let count = r.read(&mut data)?; - if count == 0 { - break; - } - - hasher.update(&data[..count]); - } - - Ok(format!("{:x}", hasher.finalize())) -} - -pub fn sha256_progress<P: AsRef<Path>>(path: P) -> Result<String> { - let len = fs::metadata(&path)?.len(); - - let mut f = fs::File::open(&path)?; - - let mut pb = ProgressBar::new(len); - pb.message("sha256: "); - pb.set_max_refresh_rate(Some(Duration::new(1, 0))); - pb.set_units(pbr::Units::Bytes); - - let res = { - let mut pbr = ProgressBarRead::new(&mut pb, &mut f); - sha256(&mut pbr) - }; - - pb.finish_println(""); - - res -}