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
79 changes: 74 additions & 5 deletions crates/rattler_conda_types/src/package/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ impl PackageFile for PathsJson {
}

fn from_str(str: &str) -> Result<Self, std::io::Error> {
serde_json::from_str(str).map_err(Into::into)
let mut paths_json: PathsJson = serde_json::from_str(str).map_err(std::io::Error::from)?;
paths_json.sort();
Ok(paths_json)
}

fn from_slice(slice: &[u8]) -> Result<Self, std::io::Error> {
serde_json::from_slice(slice).map_err(Into::into)
let mut paths_json: PathsJson =
serde_json::from_slice(slice).map_err(std::io::Error::from)?;
paths_json.sort();
Ok(paths_json)
}
}

Expand Down Expand Up @@ -107,7 +112,7 @@ impl PathsJson {
.collect();

// Iterate over all files and create entries
Ok(Self {
let mut paths_json = Self {
paths: files
.files
.into_iter()
Expand All @@ -132,7 +137,11 @@ impl PathsJson {
})
.collect::<Result<_, _>>()?,
paths_version: 1,
})
};

paths_json.sort();

Ok(paths_json)
}

/// Constructs a new instance by reading older (deprecated) files from a package directory.
Expand Down Expand Up @@ -173,6 +182,12 @@ impl PathsJson {
})
})
}

/// Sorts the entries in the `paths.json` by their relative path.
pub fn sort(&mut self) {
self.paths
.sort_by(|a, b| a.relative_path.cmp(&b.relative_path));
}
}

/// Description off a placeholder text found in a file that must be replaced when installing the
Expand Down Expand Up @@ -268,7 +283,6 @@ mod test {

#[test]
pub fn roundtrip_paths_json() {
// TODO make sure that paths.json is sorted by `_path`!
let package_dir = tempfile::tempdir().unwrap();
let package_path = tools::download_and_cache_file(
"https://conda.anaconda.org/conda-forge/win-64/mamba-1.0.0-py38hecfeebb_2.tar.bz2"
Expand Down Expand Up @@ -349,4 +363,59 @@ mod test {
paths_version: 1
});
}

#[test]
pub fn test_internal_paths_sorted() {
use super::{PathType, PathsEntry};
use std::path::PathBuf;

// test sort() method directly
let paths = vec![
PathsEntry {
relative_path: PathBuf::from("b"),
path_type: PathType::HardLink,
prefix_placeholder: None,
no_link: false,
sha256: None,
size_in_bytes: None,
},
PathsEntry {
relative_path: PathBuf::from("a"),
path_type: PathType::HardLink,
prefix_placeholder: None,
no_link: false,
sha256: None,
size_in_bytes: None,
},
];

let mut paths_json = PathsJson {
paths,
paths_version: 1,
};

// Before sorting
assert_eq!(paths_json.paths[0].relative_path, PathBuf::from("b"));

paths_json.sort();

// After sorting, entries should be in alphabetical order
assert_eq!(paths_json.paths[0].relative_path, PathBuf::from("a"));
assert_eq!(paths_json.paths[1].relative_path, PathBuf::from("b"));

// Test that from_deprecated also sorts entries
let reconstructed = PathsJson::from_deprecated(
crate::package::Files {
files: vec![PathBuf::from("z"), PathBuf::from("y")],
},
None,
None,
None,
|_| Ok::<_, std::io::Error>(PathType::HardLink),
)
.unwrap();

assert_eq!(reconstructed.paths[0].relative_path, PathBuf::from("y"));
assert_eq!(reconstructed.paths[1].relative_path, PathBuf::from("z"));
}
}
10 changes: 6 additions & 4 deletions crates/rattler_networking/src/oci_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,19 @@ impl OCIUrl {
*req.url_mut() = oci_url.blob_url(&format!("sha256:{expected_sha_hash}"))?;
} else {
// get the tag from the URL retrieve the manifest
let manifest_url = oci_url.manifest_url()?; // TODO: handle error
let manifest_url = oci_url.manifest_url()?;

let manifest = client
let manifest_response = client
.client()
.get(manifest_url)
.bearer_auth(&token)
.header(ACCEPT, "application/vnd.oci.image.manifest.v1+json")
.send()
.await?;
.await?
.error_for_status()
.map_err(OciMiddlewareError::Reqwest)?;

let manifest: Manifest = manifest.json().await?;
let manifest: Manifest = manifest_response.json().await?;

let layer = if let Some(layer) = manifest
.layers
Expand Down
5 changes: 3 additions & 2 deletions crates/rattler_upload/src/upload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ fn default_bytes_style() -> Result<indicatif::ProgressStyle, TemplateError> {
"smoothed_bytes_per_sec",
|s: &ProgressState, w: &mut dyn Write| match (s.pos(), s.elapsed().as_millis()) {
(pos, elapsed_ms) if elapsed_ms > 0 => {
// TODO: log with tracing?
_ = write!(w, "{}/s", HumanBytes((pos as f64 * 1000_f64 / elapsed_ms as f64) as u64));
let bytes_per_sec = (pos as f64 * 1000_f64 / elapsed_ms as f64) as u64;
tracing::trace!(bytes_per_sec, "upload throughput");
_ = write!(w, "{}/s", HumanBytes(bytes_per_sec));
}
_ => {
_ = write!(w, "-");
Expand Down
Loading