Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ async fn component_remove(

async fn toolchain_link(
cfg: &Cfg<'_>,
dest: &CustomToolchainName,
toolchain: &CustomToolchainName,
src: &Path,
) -> anyhow::Result<ExitCode> {
cfg.ensure_toolchains_dir()?;
Expand All @@ -1683,7 +1683,7 @@ async fn toolchain_link(

InstallMethod::Link {
src: &cfg.current_dir.join(src),
dest,
toolchain,
cfg,
}
.install(None)
Expand Down
45 changes: 22 additions & 23 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
config::Cfg,
dist::{DistOptions, manifest::ManifestWithHash, prefix::InstallPrefix},
errors::RustupError,
toolchain::{CustomToolchainName, Toolchain},
toolchain::{CustomToolchainName, LocalToolchainName, Toolchain},
utils,
};

Expand All @@ -22,7 +22,7 @@ pub(crate) enum UpdateStatus {
pub(crate) enum InstallMethod<'cfg, 'a> {
Link {
src: &'a Path,
dest: &'a CustomToolchainName,
toolchain: &'a CustomToolchainName,
cfg: &'cfg Cfg<'cfg>,
},
Dist(DistOptions<'cfg, 'a>),
Expand All @@ -45,40 +45,39 @@ impl InstallMethod<'_, '_> {
.num_threads(cfg.process.io_thread_count()?.into())
.build_global();

let local_name = match &self {
Self::Link { dest, .. } => {
let name = (*dest).clone().into();
debug!("linking toolchain {name}");
name
let toolchain = match &self {
Self::Link { toolchain, .. } => {
let toolchain = LocalToolchainName::from((*toolchain).clone());
debug!("linking toolchain `{toolchain}`");
toolchain
}
Self::Dist(DistOptions {
toolchain: desc,
toolchain,
old_date_version,
..
}) => {
let name = (*desc).clone().into();
if old_date_version.is_some() {
debug!("updating existing install for '{name}'");
} else {
debug!("installing toolchain {name}");
let toolchain = LocalToolchainName::from((*toolchain).clone());
match old_date_version {
Some(_) => debug!("updating existing install for `{toolchain}`"),
None => debug!("installing toolchain `{toolchain}`"),
}
name
toolchain
}
};

let dest_path = &cfg.toolchain_path(&local_name);
debug!("toolchain directory: {}", dest_path.display());
if dest_path.exists() && !matches!(self, Self::Dist { .. }) {
uninstall(dest_path)?;
let toolchain_path = &cfg.toolchain_path(&toolchain);
debug!("toolchain directory: {}", toolchain_path.display());
if toolchain_path.exists() && !matches!(self, Self::Dist { .. }) {
uninstall(toolchain_path)?;
}

let status = match &self {
Self::Link { src, .. } => {
utils::symlink_dir(src, dest_path)?;
utils::symlink_dir(src, toolchain_path)?;
UpdateStatus::Installed
}
Self::Dist(opts) => match opts
.install_into(&InstallPrefix::from(dest_path.clone()), manifest)
.install_into(&InstallPrefix::from(toolchain_path.clone()), manifest)
.await?
{
None => UpdateStatus::Unchanged,
Expand All @@ -96,13 +95,13 @@ impl InstallMethod<'_, '_> {
};

// Final check, to ensure we're installed
if !Toolchain::exists(cfg, &local_name)? {
return Err(RustupError::ToolchainNotInstallable(local_name.to_string()).into());
if !Toolchain::exists(cfg, &toolchain)? {
return Err(RustupError::ToolchainNotInstallable(toolchain.to_string()).into());
}

match &status {
UpdateStatus::Unchanged => debug!("toolchain is already up to date"),
_ => debug!("toolchain {local_name} installed"),
_ => debug!("toolchain {toolchain} installed"),
};

Ok(status)
Expand Down
Loading