From 18291c2aea5611e0ce166498fad3e5ac65fed1a6 Mon Sep 17 00:00:00 2001 From: Kai Lueke Date: Wed, 17 Jan 2024 12:43:58 +0100 Subject: [PATCH] Remove -v/--print-progress option The detailed report depended on async downloading which is gone and the current reporting is a single line print, not worth maintaining this command line option for. --- examples/download_test.rs | 2 +- examples/full_test.rs | 2 +- src/bin/download_sysext.rs | 18 +++++------------- src/download.rs | 34 +++++----------------------------- 4 files changed, 12 insertions(+), 44 deletions(-) diff --git a/examples/download_test.rs b/examples/download_test.rs index 367808a..7a88b17 100644 --- a/examples/download_test.rs +++ b/examples/download_test.rs @@ -13,7 +13,7 @@ fn main() -> Result<(), Box> { let tempdir = tempfile::tempdir()?; let path = tempdir.path().join("tmpfile"); - let res = download_and_hash(&client, url, &path, None, None, false)?; + let res = download_and_hash(&client, url, &path, None, None)?; tempdir.close()?; println!("hash: {}", res.hash_sha256); diff --git a/examples/full_test.rs b/examples/full_test.rs index 319ae4a..17ce5c4 100644 --- a/examples/full_test.rs +++ b/examples/full_test.rs @@ -80,7 +80,7 @@ fn main() -> Result<(), Box> { let tempdir = tempfile::tempdir()?; let path = tempdir.path().join("tmpfile"); - let res = ue_rs::download_and_hash(&client, url.clone(), &path, Some(expected_sha256.clone()), None, false).context(format!("download_and_hash({url:?}) failed"))?; + let res = ue_rs::download_and_hash(&client, url.clone(), &path, Some(expected_sha256.clone()), None).context(format!("download_and_hash({url:?}) failed"))?; tempdir.close()?; println!("\texpected sha256: {}", expected_sha256); diff --git a/src/bin/download_sysext.rs b/src/bin/download_sysext.rs index 304b771..7a258ad 100644 --- a/src/bin/download_sysext.rs +++ b/src/bin/download_sysext.rs @@ -98,7 +98,7 @@ impl<'a> Package<'a> { Ok(()) } - fn download(&mut self, into_dir: &Path, client: &Client, print_progress: bool) -> Result<()> { + fn download(&mut self, into_dir: &Path, client: &Client) -> Result<()> { // FIXME: use _range_start for completing downloads let _range_start = match self.status { PackageStatus::ToDownload => 0, @@ -115,7 +115,6 @@ impl<'a> Package<'a> { &path, self.hash_sha256.clone(), self.hash_sha1.clone(), - print_progress, ) { Ok(ok) => ok, Err(err) => { @@ -251,12 +250,12 @@ fn get_pkgs_to_download<'a>(resp: &'a omaha::Response, glob_set: &GlobSet) } // Read data from remote URL into File -fn fetch_url_to_file<'a, U>(path: &'a Path, input_url: U, client: &'a Client, print_progress: bool) -> Result> +fn fetch_url_to_file<'a, U>(path: &'a Path, input_url: U, client: &'a Client) -> Result> where U: reqwest::IntoUrl + From + std::clone::Clone + std::fmt::Debug, Url: From, { - let r = ue_rs::download_and_hash(client, input_url.clone(), path, None, None, print_progress).context(format!("unable to download data(url {:?})", input_url))?; + let r = ue_rs::download_and_hash(client, input_url.clone(), path, None, None).context(format!("unable to download data(url {:?})", input_url))?; Ok(Package { name: Cow::Borrowed(path.file_name().unwrap_or(OsStr::new("fakepackage")).to_str().unwrap_or("fakepackage")), @@ -268,10 +267,10 @@ where }) } -fn do_download_verify(pkg: &mut Package<'_>, output_filename: Option, output_dir: &Path, unverified_dir: &Path, pubkey_file: &str, client: &Client, print_progress: bool) -> Result<()> { +fn do_download_verify(pkg: &mut Package<'_>, output_filename: Option, output_dir: &Path, unverified_dir: &Path, pubkey_file: &str, client: &Client) -> Result<()> { pkg.check_download(unverified_dir)?; - pkg.download(unverified_dir, client, print_progress).context(format!("unable to download \"{:?}\"", pkg.name))?; + pkg.download(unverified_dir, client).context(format!("unable to download \"{:?}\"", pkg.name))?; // Unverified payload is stored in e.g. "output_dir/.unverified/oem.gz". // Verified payload is stored in e.g. "output_dir/oem.raw". @@ -319,10 +318,6 @@ struct Args { /// only take the first matching entry #[argh(switch, short = 't')] take_first_match: bool, - - /// report download progress - #[argh(switch, short = 'v')] - print_progress: bool, } impl Args { @@ -399,7 +394,6 @@ fn main() -> Result<(), Box> { &temp_payload_path, Url::from_str(url.as_str()).context(anyhow!("failed to convert into url ({:?})", url))?, &client, - args.print_progress, )?; do_download_verify( &mut pkg_fake, @@ -408,7 +402,6 @@ fn main() -> Result<(), Box> { unverified_dir.as_path(), args.pubkey_file.as_str(), &client, - args.print_progress, )?; // verify only a fake package, early exit and skip the rest. @@ -442,7 +435,6 @@ fn main() -> Result<(), Box> { unverified_dir.as_path(), args.pubkey_file.as_str(), &client, - args.print_progress, )?; if args.take_first_match { break; diff --git a/src/download.rs b/src/download.rs index 7b2fdac..04b7448 100644 --- a/src/download.rs +++ b/src/download.rs @@ -59,14 +59,7 @@ pub fn hash_on_disk(path: &Path, maxlen: Option) -> R Ok(omaha::Hash::from_bytes(Box::new(hasher).finalize())) } -fn do_download_and_hash( - client: &Client, - url: U, - path: &Path, - expected_sha256: Option>, - expected_sha1: Option>, - print_progress: bool, -) -> Result +fn do_download_and_hash(client: &Client, url: U, path: &Path, expected_sha256: Option>, expected_sha1: Option>) -> Result where U: reqwest::IntoUrl + Clone, Url: From, @@ -96,9 +89,8 @@ where } } - if print_progress { - println!("writing to {}", path.display()); - } + println!("writing to {}", path.display()); + let mut file = File::create(path).context(format!("failed to create path ({:?})", path.display()))?; res.copy_to(&mut file)?; @@ -126,29 +118,13 @@ where }) } -pub fn download_and_hash( - client: &Client, - url: U, - path: &Path, - expected_sha256: Option>, - expected_sha1: Option>, - print_progress: bool, -) -> Result +pub fn download_and_hash(client: &Client, url: U, path: &Path, expected_sha256: Option>, expected_sha1: Option>) -> Result where U: reqwest::IntoUrl + Clone, Url: From, { crate::retry_loop( - || { - do_download_and_hash( - client, - url.clone(), - path, - expected_sha256.clone(), - expected_sha1.clone(), - print_progress, - ) - }, + || do_download_and_hash(client, url.clone(), path, expected_sha256.clone(), expected_sha1.clone()), MAX_DOWNLOAD_RETRY, ) }