Don't show progress bar on normal read

This commit is contained in:
Wildan M 2025-10-11 21:13:14 +07:00
parent d20b16037e
commit 25dd3b79a1
2 changed files with 18 additions and 5 deletions

View File

@ -21,3 +21,11 @@ pub fn blake3_progress<P: AsRef<Path>>(path: P) -> Result<String> {
Ok(res)
}
pub fn blake3_silent<P: AsRef<Path>>(path: P) -> Result<String> {
let mut f = fs::File::open(&path)?;
let hash = Hasher::new().update_reader(&mut f)?.finalize();
let res = format!("{}", hash.to_hex());
Ok(res)
}

View File

@ -3,13 +3,18 @@ use crate::cook::fs::*;
use crate::cook::script::*;
use crate::is_redox;
use crate::recipe::Recipe;
use crate::{blake3::blake3_progress, recipe::SourceRecipe};
use crate::{blake3, recipe::SourceRecipe};
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
pub(crate) fn get_blake3(path: &PathBuf) -> Result<String, String> {
blake3_progress(&path).map_err(|err| {
pub(crate) fn get_blake3(path: &PathBuf, show_progress: bool) -> Result<String, String> {
if show_progress {
blake3::blake3_progress(&path)
} else {
blake3::blake3_silent(&path)
}
.map_err(|err| {
format!(
"failed to calculate blake3 of '{}': {}\n{:?}",
path.display(),
@ -52,7 +57,7 @@ pub fn fetch_offline(recipe_dir: &Path, source: &Option<SourceRecipe>) -> Result
}) => {
if !source_dir.is_dir() {
let source_tar = recipe_dir.join("source.tar");
let source_tar_blake3 = get_blake3(&source_tar)?;
let source_tar_blake3 = get_blake3(&source_tar, true)?;
if source_tar.exists() {
if let Some(blake3) = blake3 {
if source_tar_blake3 != *blake3 {
@ -237,7 +242,7 @@ pub fn fetch(recipe_dir: &Path, source: &Option<SourceRecipe>) -> Result<PathBuf
rename(&source_tar_tmp, &source_tar)?;
}
}
let source_tar_blake3 = get_blake3(&source_tar)?;
let source_tar_blake3 = get_blake3(&source_tar, tar_updated)?;
if let Some(blake3) = blake3 {
if source_tar_blake3 != *blake3 {
if tar_updated {