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
9 changes: 5 additions & 4 deletions crates/rattler-bin/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rattler::{
};
use rattler_conda_types::{
Channel, ChannelConfig, GenericVirtualPackage, MatchSpec, Matches, PackageName,
ParseMatchSpecOptions, Platform, PrefixRecord, RepoDataRecord, Version,
ParseMatchSpecOptions, Platform, PrefixRecord, RepoDataRecord, Version, package::BuildString,
};
use rattler_repodata_gateway::{Gateway, RepoData, SourceConfig};
use rattler_solve::{
Expand Down Expand Up @@ -236,7 +236,7 @@ pub async fn create(opt: Opt) -> miette::Result<()> {
.get(1)
.map_or(Version::from_str("0"), |s| Version::from_str(s))
.into_diagnostic()?,
build_string: (*elems.get(2).unwrap_or(&"")).to_string(),
build_string: BuildString::new_unchecked(*elems.get(2).unwrap_or(&"")),
})
})
.collect::<miette::Result<Vec<_>>>()?)
Expand Down Expand Up @@ -367,21 +367,22 @@ fn print_transaction(
String::new()
};

let build = r.package_record.build.to_string();
if let Some(features) = features.get(&r.package_record.name) {
format!(
"{}[{}] {} {} {}",
r.package_record.name.as_normalized(),
features.join(", "),
r.package_record.version,
r.package_record.build,
build,
direct_url_print,
)
} else {
format!(
"{} {} {} {}",
r.package_record.name.as_normalized(),
r.package_record.version,
r.package_record.build,
build,
direct_url_print,
)
}
Expand Down
3 changes: 2 additions & 1 deletion crates/rattler-bin/src/commands/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,11 @@ pub async fn search(opt: Opt) -> miette::Result<()> {

for record in records.iter().take(limit_versions) {
let channel = record.channel.as_deref().unwrap_or("unknown");
let build = record.package_record.build.to_string();
println!(
" {} {} [{}] {}",
console::style(&record.package_record.version).cyan(),
record.package_record.build,
build,
record.package_record.subdir,
console::style(channel).dim()
);
Expand Down
44 changes: 25 additions & 19 deletions crates/rattler/src/install/installer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,16 @@ impl Installer {
.installed_packages()
.filter(|record| record.package_record.subdir != "noarch")
.map(|record| {
format!(
"{}/{}-{}-{}",
record.package_record.subdir,
record.package_record.name.as_normalized(),
record.package_record.version,
record.package_record.build
)
let package_record = &record.package_record;
let subdir = &package_record.subdir;
let name = package_record.name.as_normalized();
let version = &package_record.version;
let build = &package_record.build;
if build.is_empty() {
format!("{subdir}/{name}-{version}")
} else {
format!("{subdir}/{name}-{version}-{build}")
}
})
.collect();

Expand Down Expand Up @@ -978,12 +981,14 @@ fn update_existing_records<'p>(
// Write the updated record back to disk if needed
if let Some(new_record) = updated_record {
let conda_meta_path = prefix.path().join("conda-meta");
let pkg_meta_path = format!(
"{}-{}-{}.json",
new_record.name().as_normalized(),
new_record.version(),
new_record.build()
);
let name = new_record.name().as_normalized();
let version = new_record.version();
let build = new_record.build();
let pkg_meta_path = if build.is_empty() {
format!("{name}-{version}.json")
} else {
format!("{name}-{version}-{build}.json")
};
let full_path = conda_meta_path.join(&pkg_meta_path);

// We need to do a targeted update of just the requested_specs fields
Expand Down Expand Up @@ -1055,12 +1060,13 @@ mod tests {
repo_record: &rattler_conda_types::RepoDataRecord,
) -> std::path::PathBuf {
let conda_meta_path = prefix.path().join("conda-meta");
let expected_filename = format!(
"{}-{}-{}.json",
repo_record.package_record.name.as_normalized(),
repo_record.package_record.version,
repo_record.package_record.build
);
let record = &repo_record.package_record;
let name = record.name.as_normalized();
let expected_filename = if record.build.is_empty() {
format!("{name}-{}.json", record.version)
} else {
format!("{name}-{}-{}.json", record.version, record.build)
};
conda_meta_path.join(&expected_filename)
}

Expand Down
36 changes: 20 additions & 16 deletions crates/rattler/src/install/installer/result_record.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{io, path::Path};

use rattler_conda_types::package::BuildString;
use rattler_conda_types::{
HasArtifactIdentificationRefs, MinimalPrefixRecord, PrefixRecord, RepoDataRecord,
};
Expand Down Expand Up @@ -31,12 +32,14 @@ impl InstallationResultRecord {
match self {
InstallationResultRecord::Max(prefix_record) => Ok(prefix_record),
InstallationResultRecord::Min(minimal_prefix_record) => {
let record_name = format!(
"{build}-{version}-{name}.json",
build = minimal_prefix_record.build,
version = minimal_prefix_record.version,
name = minimal_prefix_record.name.as_normalized()
);
let name = minimal_prefix_record.name.as_normalized();
let version = &minimal_prefix_record.version;
let build = &minimal_prefix_record.build;
let record_name = if build.is_empty() {
format!("{version}-{name}.json")
} else {
format!("{build}-{version}-{name}.json")
};
let record_path = prefix.as_ref().join(record_name);
PrefixRecord::from_path(record_path)
}
Expand All @@ -63,8 +66,9 @@ impl InstallationResultRecord {
}
}

/// Return reference to the underlying build string.
pub fn build(&self) -> &str {
/// Return reference to the underlying build string. Empty when the
/// package has no build identifier.
pub fn build(&self) -> &BuildString {
match self {
InstallationResultRecord::Max(prefix_record) => {
&prefix_record.repodata_record.package_record.build
Expand Down Expand Up @@ -176,7 +180,7 @@ impl InstallationResultRecord {
pub trait ContentComparable {
fn name(&self) -> &PackageName;
fn version(&self) -> &VersionWithSource;
fn build(&self) -> &str;
fn build(&self) -> &BuildString;
fn sha256(&self) -> Option<&Sha256Hash>;
fn md5(&self) -> Option<&Md5Hash>;
fn size(&self) -> Option<u64>;
Expand All @@ -193,7 +197,7 @@ impl ContentComparable for InstallationResultRecord {
self.version()
}

fn build(&self) -> &str {
fn build(&self) -> &BuildString {
self.build()
}

Expand Down Expand Up @@ -225,7 +229,7 @@ impl ContentComparable for PackageRecord {
fn version(&self) -> &VersionWithSource {
&self.version
}
fn build(&self) -> &str {
fn build(&self) -> &BuildString {
&self.build
}
fn sha256(&self) -> Option<&Sha256Hash> {
Expand All @@ -252,7 +256,7 @@ impl ContentComparable for MinimalPrefixRecord {
fn version(&self) -> &VersionWithSource {
&self.version
}
fn build(&self) -> &str {
fn build(&self) -> &BuildString {
&self.build
}
fn sha256(&self) -> Option<&Sha256Hash> {
Expand All @@ -279,7 +283,7 @@ impl ContentComparable for PrefixRecord {
fn version(&self) -> &VersionWithSource {
&self.repodata_record.package_record.version
}
fn build(&self) -> &str {
fn build(&self) -> &BuildString {
&self.repodata_record.package_record.build
}
fn sha256(&self) -> Option<&Sha256Hash> {
Expand Down Expand Up @@ -309,7 +313,7 @@ impl ContentComparable for RepoDataRecord {
fn version(&self) -> &VersionWithSource {
&self.package_record.version
}
fn build(&self) -> &str {
fn build(&self) -> &BuildString {
&self.package_record.build
}
fn sha256(&self) -> Option<&Sha256Hash> {
Expand All @@ -336,7 +340,7 @@ impl<T: ContentComparable> ContentComparable for &T {
fn version(&self) -> &VersionWithSource {
(*self).version()
}
fn build(&self) -> &str {
fn build(&self) -> &BuildString {
(*self).build()
}
fn sha256(&self) -> Option<&Sha256Hash> {
Expand Down Expand Up @@ -365,7 +369,7 @@ impl HasArtifactIdentificationRefs for InstallationResultRecord {
InstallationResultRecord::version(self)
}

fn build(&self) -> &str {
fn build(&self) -> &BuildString {
InstallationResultRecord::build(self)
}
}
2 changes: 1 addition & 1 deletion crates/rattler_cache/src/package_cache/cache_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl From<&PackageRecord> for CacheKey {
Self {
name: record.name.as_normalized().to_string(),
version: record.version.to_string(),
build_string: record.build.clone(),
build_string: record.build.to_string(),
sha256: record.sha256,
md5: record.md5,
origin_hash: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_cache/src/run_exports_cache/cache_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl CacheKey {
Ok(Self {
name: record.name.as_normalized().to_string(),
version: record.version.to_string(),
build_string: record.build.clone(),
build_string: record.build.to_string(),
sha256: record.sha256,
md5: record.md5,
extension: archive_identifier.archive_type.extension().to_string(),
Expand Down
14 changes: 7 additions & 7 deletions crates/rattler_cache/src/run_exports_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ mod test {
routing::get,
};

use rattler_conda_types::{PackageName, PackageRecord, Version};
use rattler_conda_types::{PackageName, PackageRecord, Version, package::BuildString};
use rattler_digest::{Sha256, parse_digest_from_hex};
use rattler_networking::retry_policies::{DoNotRetryPolicy, ExponentialBackoffBuilder};
use reqwest::Client;
Expand Down Expand Up @@ -423,7 +423,7 @@ mod test {
let mut pkg_record = PackageRecord::new(
PackageName::from_str("ros-noetic-rosbridge-suite").unwrap(),
Version::from_str("0.11.14").unwrap(),
"py39h6fdeb60_14".to_string(),
BuildString::new("py39h6fdeb60_14").unwrap(),
);
pkg_record.sha256 = Some(
parse_digest_from_hex::<Sha256>(
Expand Down Expand Up @@ -467,7 +467,7 @@ mod test {
let pkg_record = PackageRecord::new(
PackageName::from_str("zlib").unwrap(),
Version::from_str("1.3.1").unwrap(),
"hb9d3cd8_2".to_string(),
BuildString::new("hb9d3cd8_2").unwrap(),
);

let cache_key = CacheKey::create(&pkg_record, "zlib-1.3.1-hb9d3cd8_2.conda").unwrap();
Expand Down Expand Up @@ -609,13 +609,13 @@ mod test {
let tar_record = PackageRecord::new(
PackageName::from_str("conda").unwrap(),
Version::from_str("22.9.0").unwrap(),
"py310h5588dad_2".to_string(),
BuildString::new("py310h5588dad_2").unwrap(),
);

let conda_record = PackageRecord::new(
PackageName::from_str("conda").unwrap(),
Version::from_str("22.11.1").unwrap(),
"py38haa244fe_1".to_string(),
BuildString::new("py38haa244fe_1").unwrap(),
);

test_flaky_package_cache(tar_bz2, &tar_record, Middleware::FailTheFirstTwoRequests).await;
Expand All @@ -631,7 +631,7 @@ mod test {
let mut pkg_record = PackageRecord::new(
PackageName::from_str("ros-noetic-rosbridge-suite").unwrap(),
Version::from_str("0.11.14").unwrap(),
"py39h6fdeb60_14".to_string(),
BuildString::new("py39h6fdeb60_14").unwrap(),
);
pkg_record.sha256 = Some(
parse_digest_from_hex::<Sha256>(
Expand Down Expand Up @@ -709,7 +709,7 @@ mod test {
let pkg_record = PackageRecord::new(
PackageName::from_str("zlib").unwrap(),
Version::from_str("1.3.1").unwrap(),
"hb9d3cd8_2".to_string(),
BuildString::new("hb9d3cd8_2").unwrap(),
);

let cache_key = CacheKey::create(&pkg_record, "zlib-1.3.1-hb9d3cd8_2.conda").unwrap();
Expand Down
17 changes: 7 additions & 10 deletions crates/rattler_conda_types/benches/prefix_record_from_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,13 @@ fn criterion_benchmark(c: &mut Criterion) {
super_long_file.files.extend(files.clone());
}

let filename = format!(
"{}-{}-{}.json",
super_long_file
.repodata_record
.package_record
.name
.as_normalized(),
super_long_file.repodata_record.package_record.version,
super_long_file.repodata_record.package_record.build
);
let record = &super_long_file.repodata_record.package_record;
let name = record.name.as_normalized();
let filename = if record.build.is_empty() {
format!("{name}-{}.json", record.version)
} else {
format!("{name}-{}-{}.json", record.version, record.build)
};
let new_long_file_path = temp_dir.path().join(filename);
serde_json::to_writer(File::create(&new_long_file_path).unwrap(), &super_long_file).unwrap();

Expand Down
Loading
Loading