Skip to content

Commit

Permalink
Fix reading env CARGO_REGISTRIES_{registry_name}_INDEX (#1258)
Browse files Browse the repository at this point in the history
Try bogth original and upper-case version.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
  • Loading branch information
NobodyXu authored Aug 9, 2023
1 parent 939c9b4 commit a9e2ef1
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions crates/bin/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,29 @@ pub fn install_crates(
.registry
.or_else(|| config.registry.and_then(|registry| registry.default))
{
env::var(format!("CARGO_REGISTRIES_{registry_name}_INDEX"))
.map(Cow::Owned)
.or_else(|_| {
config
.registries
.as_ref()
.and_then(|registries| registries.get(&registry_name))
.and_then(|registry| registry.index.as_deref().map(Cow::Borrowed))
.ok_or_else(|| BinstallError::UnknownRegistryName(registry_name))
})?
.parse()
.map_err(BinstallError::from)?
let registry_name_lowercase = registry_name.to_lowercase();

let v = env::vars().find_map(|(k, v)| {
let name_lowercase = k
.strip_prefix("CARGO_REGISTRIES_")?
.strip_suffix("_INDEX")?
.to_lowercase();

(name_lowercase == registry_name_lowercase).then_some(v)
});

if let Some(v) = &v {
v
} else {
config
.registries
.as_ref()
.and_then(|registries| registries.get(&registry_name))
.and_then(|registry| registry.index.as_deref())
.ok_or_else(|| BinstallError::UnknownRegistryName(registry_name))?
}
.parse()
.map_err(BinstallError::from)?
} else {
Default::default()
},
Expand Down

0 comments on commit a9e2ef1

Please sign in to comment.