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
16 changes: 6 additions & 10 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,17 +1679,13 @@ async fn toolchain_link(
pathbuf.push(format!("rustc{EXE_SUFFIX}"));
utils::assert_is_file(&pathbuf)?;

if true {
InstallMethod::Link {
src: &cfg.current_dir.join(src),
dest,
cfg,
}
.install(None)
.await?;
} else {
InstallMethod::Copy { src, dest, cfg }.install(None).await?;
InstallMethod::Link {
src: &cfg.current_dir.join(src),
dest,
cfg,
}
.install(None)
.await?;

Ok(ExitCode::SUCCESS)
}
Expand Down
49 changes: 12 additions & 37 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ pub(crate) enum UpdateStatus {
}

pub(crate) enum InstallMethod<'cfg, 'a> {
Copy {
src: &'a Path,
dest: &'a CustomToolchainName,
cfg: &'cfg Cfg<'cfg>,
},
Link {
src: &'a Path,
dest: &'a CustomToolchainName,
Expand All @@ -45,14 +40,14 @@ impl InstallMethod<'_, '_> {
let _ = rayon::ThreadPoolBuilder::new()
.num_threads(self.cfg().process.io_thread_count()?.into())
.build_global();
let local_name = self.local_name();
match &self {
InstallMethod::Copy { .. }
| InstallMethod::Link { .. }
InstallMethod::Link { .. }
| InstallMethod::Dist(DistOptions {
old_date_version: None,
..
}) => debug!("installing toolchain {}", self.dest_basename()),
_ => debug!("updating existing install for '{}'", self.dest_basename()),
}) => debug!("installing toolchain {local_name}",),
_ => debug!("updating existing install for '{local_name}'"),
}

debug!("toolchain directory: {}", self.dest_path().display());
Expand All @@ -64,23 +59,23 @@ impl InstallMethod<'_, '_> {
UpdateStatus::Unchanged
}
true => {
debug!("toolchain {} installed", self.dest_basename());
debug!("toolchain {local_name} installed");
match &self {
InstallMethod::Dist(DistOptions {
old_date_version: Some((_, v)),
..
}) => UpdateStatus::Updated(v.clone()),
InstallMethod::Copy { .. }
| InstallMethod::Link { .. }
| InstallMethod::Dist { .. } => UpdateStatus::Installed,
InstallMethod::Link { .. } | InstallMethod::Dist { .. } => {
UpdateStatus::Installed
}
}
}
};

// Final check, to ensure we're installed
match Toolchain::exists(self.cfg(), &self.local_name())? {
match Toolchain::exists(self.cfg(), &local_name)? {
true => Ok(status),
false => Err(RustupError::ToolchainNotInstallable(self.dest_basename()).into()),
false => Err(RustupError::ToolchainNotInstallable(local_name.to_string()).into()),
}
}

Expand All @@ -96,10 +91,6 @@ impl InstallMethod<'_, '_> {
}

match self {
InstallMethod::Copy { src, .. } => {
utils::copy_dir(src, path)?;
Ok(true)
}
InstallMethod::Link { src, .. } => {
utils::symlink_dir(src, path)?;
Ok(true)
Expand All @@ -120,38 +111,22 @@ impl InstallMethod<'_, '_> {

fn cfg(&self) -> &Cfg<'_> {
match self {
InstallMethod::Copy { cfg, .. } => cfg,
InstallMethod::Link { cfg, .. } => cfg,
InstallMethod::Dist(DistOptions { cfg, .. }) => cfg,
}
}

fn local_name(&self) -> LocalToolchainName {
match self {
InstallMethod::Copy { dest, .. } | InstallMethod::Link { dest, .. } => {
(*dest).clone().into()
}
InstallMethod::Link { dest, .. } => (*dest).clone().into(),
InstallMethod::Dist(DistOptions {
toolchain: desc, ..
}) => (*desc).clone().into(),
}
}

fn dest_basename(&self) -> String {
self.local_name().to_string()
}

fn dest_path(&self) -> PathBuf {
match self {
InstallMethod::Copy { cfg, dest, .. } | InstallMethod::Link { cfg, dest, .. } => {
cfg.toolchain_path(&(*dest).clone().into())
}
InstallMethod::Dist(DistOptions {
cfg,
toolchain: desc,
..
}) => cfg.toolchain_path(&(*desc).clone().into()),
}
self.cfg().toolchain_path(&self.local_name())
}
}

Expand Down
Loading