Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/rattler_package_streaming/src/tokio/async_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
35 changes: 27 additions & 8 deletions crates/rattler_package_streaming/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>, Vec<PathBuf>) {
fn sort_paths(
paths: &[PathBuf],
base_path: &Path,
) -> Result<(Vec<PathBuf>, Vec<PathBuf>), 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::<Result<Vec<_>, _>>()?;

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 {
Expand Down Expand Up @@ -146,7 +165,7 @@ pub fn write_tar_bz2_package<W: Write>(
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,
Expand Down Expand Up @@ -281,7 +300,7 @@ pub fn write_conda_package<W: Write + Seek>(
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");

Expand Down
Loading