Skip to content

Commit

Permalink
Fix clobbering of process vs component vs forc (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfiedotwtf committed Oct 4, 2024
1 parent 24064ac commit e5318c2
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/proxy_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,34 @@ fn direct_proxy(proc_name: &str, args: &[OsString], toolchain: &Toolchain) -> Re
// Install the entire toolchain declared in [toolchain] if it does not exist.
toolchain.install_if_nonexistent(&description)?;

// Plugins distributed by forc have to be handled a little differently,
// if one of them is called we want to check for 'forc' instead.
let component_name = if Component::is_distributed_by_forc(proc_name) {
component::FORC
} else {
proc_name
};
// If a specific version is declared, we want to call it from the
// store and not from the toolchain directory.
if let Some(version) = to.get_component_version(proc_name) {
let component = match Component::resolve_from_name(proc_name) {
Some(component) => component,
None => {
return Err(Error::new(
ErrorKind::NotFound,
format!("Component '{proc_name}' with version '{version}' not found"),
)
.into());
}
};

// If a specific version is declared, we want to call it from the store and not from the toolchain directory.
if let Some(version) = to.get_component_version(component_name) {
let store = Store::from_env()?;

if !store.has_component(component_name, version) {
if !store.has_component(&component.name, version) {
let download_cfg = DownloadCfg::new(
component_name,
TargetTriple::from_component(component_name)?,
&component.name,
TargetTriple::from_component(&component.name)?,
Some(version.clone()),
)?;
// Install components within [components] that are declared but missing from the store.
store.install_component(&download_cfg)?;
};
}

(
store
.component_dir_path(component_name, version)
.component_dir_path(&component.name, version)
.join(proc_name),
description.to_string(),
)
Expand All @@ -94,7 +97,7 @@ fn direct_proxy(proc_name: &str, args: &[OsString], toolchain: &Toolchain) -> Re
ErrorKind::NotFound => Err(Error::new(
ErrorKind::NotFound,
format!(
"component '{proc_name}' not found in currently active toolchain '{toolchain_name}'"
"Component '{proc_name}' not found in currently active toolchain '{toolchain_name}'"
),
)),
_ => Err(error),
Expand Down

0 comments on commit e5318c2

Please sign in to comment.