diff --git a/crates/rattler_package_streaming/src/tokio/async_read.rs b/crates/rattler_package_streaming/src/tokio/async_read.rs index d2e51647f..2c969585e 100644 --- a/crates/rattler_package_streaming/src/tokio/async_read.rs +++ b/crates/rattler_package_streaming/src/tokio/async_read.rs @@ -6,9 +6,10 @@ use std::path::Path; use async_compression::tokio::bufread::BzDecoder; use async_spooled_tempfile::SpooledTempFile; use async_zip::base::read::stream::ZipFileReader; -use futures_util::StreamExt; -use tokio::io::{AsyncRead, AsyncReadExt, AsyncSeekExt}; +use tokio::io::{AsyncRead, AsyncSeekExt}; use tokio_util::compat::{FuturesAsyncReadCompatExt, TokioAsyncReadCompatExt}; +#[cfg(feature = "reqwest")] +use {futures_util::StreamExt as _, tokio::io::AsyncReadExt}; use crate::{read::SizeCountingReader, ExtractError, ExtractResult}; diff --git a/crates/rattler_package_streaming/src/write.rs b/crates/rattler_package_streaming/src/write.rs index 70437f5d3..09d516d87 100644 --- a/crates/rattler_package_streaming/src/write.rs +++ b/crates/rattler_package_streaming/src/write.rs @@ -70,18 +70,37 @@ impl Read for ProgressBarReader { /// a function that sorts paths into two iterators, one that starts with `info/` /// and one that does not both iterators are sorted alphabetically for /// reproducibility -fn sort_paths<'a>(paths: &'a [PathBuf], base_path: &'a Path) -> (Vec, Vec) { +fn sort_paths( + paths: &[PathBuf], + base_path: &Path, +) -> Result<(Vec, Vec), io::Error> { let info = Path::new("info/"); - let (mut info_paths, mut other_paths): (Vec<_>, Vec<_>) = paths + let relative_paths = paths .iter() - .map(|p| p.strip_prefix(base_path).unwrap()) - .map(Path::to_path_buf) - .partition(|path| path.starts_with(info)); + .map(|p| { + p.strip_prefix(base_path) + .map(Path::to_path_buf) + .map_err(|_e| { + io::Error::new( + io::ErrorKind::InvalidInput, + format!( + "path '{}' is not under base path '{}'", + p.display(), + base_path.display() + ), + ) + }) + }) + .collect::, _>>()?; + + let (mut info_paths, mut other_paths): (Vec<_>, Vec<_>) = relative_paths + .into_iter() + .partition(|p| p.starts_with(info)); info_paths.sort(); other_paths.sort(); - (info_paths, other_paths) + Ok((info_paths, other_paths)) } fn total_size(base_path: &Path, paths: &[PathBuf]) -> u64 { @@ -146,7 +165,7 @@ pub fn write_tar_bz2_package( progress_bar_wrapper.set_total(total_size); // sort paths alphabetically, and sort paths beginning with `info/` first - let (info_paths, other_paths) = sort_paths(paths, base_path); + let (info_paths, other_paths) = sort_paths(paths, base_path)?; for path in info_paths.iter().chain(other_paths.iter()) { append_path_to_archive( &mut archive, @@ -281,7 +300,7 @@ pub fn write_conda_package( outer_archive.start_file("metadata.json", options)?; outer_archive.write_all(package_metadata.as_bytes())?; - let (info_paths, other_paths) = sort_paths(paths, base_path); + let (info_paths, other_paths) = sort_paths(paths, base_path)?; let archive_path = format!("pkg-{out_name}.tar.zst");