diff --git a/src/helpers.rs b/src/helpers.rs index 643eda60..7a222d3f 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -86,36 +86,6 @@ pub async fn download_and_extract>( Ok(()) } -/// Download a file from the provided URL and extract part of it to -/// the provided path. -/// -/// * `filter` - It will pass the path of the file to it -/// and only extract ones which filter returns `true`. -pub async fn download_and_extract_with_filter< - Filter: FnMut(&Path) -> bool + Send + 'static, - P: AsRef, ->( - url: Url, - fmt: TarBasedFmt, - path: P, - filter: Filter, -) -> Result<(), BinstallError> { - debug!("Downloading from: '{url}'"); - - let resp = create_request(url).await?; - - let path = path.as_ref(); - debug!("Downloading to file: '{}'", path.display()); - - let stream = resp.bytes_stream(); - - extract_tar_based_stream_with_filter(stream, path, fmt, filter).await?; - - debug!("Download OK, written to file: '{}'", path.display()); - - Ok(()) -} - /// Download a file from the provided URL and extract part of it to /// the provided path. /// diff --git a/src/helpers/async_extracter.rs b/src/helpers/async_extracter.rs index cdf8ffea..8564d19e 100644 --- a/src/helpers/async_extracter.rs +++ b/src/helpers/async_extracter.rs @@ -1,12 +1,10 @@ use std::fmt::Debug; use std::fs; use std::io::{self, Read, Seek, Write}; -use std::path::{Path, PathBuf}; -use std::sync::Arc; +use std::path::Path; use bytes::Bytes; use futures_util::stream::{Stream, StreamExt}; -use log::debug; use scopeguard::{guard, ScopeGuard}; use tar::Entries; use tempfile::tempfile; @@ -203,55 +201,6 @@ where .await } -/// * `filter` - If Some, then it will pass the path of the file to it -/// and only extract ones which filter returns `true`. -pub async fn extract_tar_based_stream_with_filter< - Filter: FnMut(&Path) -> bool + Send + 'static, - E, ->( - stream: impl Stream> + Unpin, - output: &Path, - fmt: TarBasedFmt, - filter: Filter, -) -> Result<(), BinstallError> -where - BinstallError: From, -{ - struct Visitor(F, Arc); - - impl bool + Send + 'static> TarEntriesVisitor for Visitor { - fn visit(&mut self, entries: Entries<'_, R>) -> Result<(), BinstallError> { - for res in entries { - let mut entry = res?; - let entry_path = entry.path()?; - - if self.0(&entry_path) { - debug!("Extracting {entry_path:#?}"); - - let dst = self.1.join(entry_path); - - fs::create_dir_all(dst.parent().unwrap())?; - - entry.unpack(dst)?; - } - } - - Ok(()) - } - } - - let path = Arc::new(output.to_owned()); - - let visitor = Visitor(filter, path.clone()); - - extract_impl(stream, move |mut rx| { - fs::create_dir_all(path.parent().unwrap())?; - - extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt, &*path, Some(visitor)) - }) - .await -} - pub async fn extract_tar_based_stream( stream: impl Stream> + Unpin, output: &Path,