From 6e5538076d9a2365c36f2e1a06dbb81d617d1e71 Mon Sep 17 00:00:00 2001 From: Alfie John Date: Mon, 28 Oct 2024 02:53:54 +1100 Subject: [PATCH] Fix incorrect binary link target (#654) When a proxy CLI'd command downloads a missing toolchain, multiple binary files within the downloaded distribution were being symlinked to the same one target file (thus overwriting each previous target). --- src/toolchain.rs | 17 ++++++++++------- tests/toolchain.rs | 4 ---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/toolchain.rs b/src/toolchain.rs index bfe1563d..61e25316 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -385,16 +385,19 @@ impl Toolchain { let store = Store::from_env()?; for cfg in channel.build_download_configs() { if store.has_component(&cfg.name, &cfg.version) { - hard_or_symlink_file( - &store - .component_dir_path(&cfg.name, &cfg.version) - .join(&cfg.name), - &self.bin_path.join(&cfg.name), - )?; + self.add_component(cfg)?; } else { let downloaded = store.install_component(&cfg)?; for bin in downloaded { - hard_or_symlink_file(&bin, &self.bin_path.join(&cfg.name))?; + // Use the actual binary filename rather than the + // config name to prevent multiple binaries from + // being linked to the same target file. + match bin.file_name() { + None => bail!("Failed to read file '{bin:?}' from download"), + Some(executable) => { + hard_or_symlink_file(&bin, &self.bin_path.join(executable))? + } + } } } } diff --git a/tests/toolchain.rs b/tests/toolchain.rs index 4a514391..f69fca87 100644 --- a/tests/toolchain.rs +++ b/tests/toolchain.rs @@ -181,13 +181,11 @@ fn direct_proxy_install_toolchain_in_store_publishable() { } #[test] -#[should_panic] // TODO: #654 will fix this fn direct_proxy_install_toolchain_in_store_forc_plugin() { test_direct_proxy_install_toolchain_in_store(Some("forc-client")); } #[test] -#[should_panic] // TODO: #654 will fix this fn direct_proxy_install_toolchain_in_store_forc_plugin_external() { test_direct_proxy_install_toolchain_in_store(Some("forc-tx")); } @@ -208,13 +206,11 @@ fn direct_proxy_install_toolchain_not_in_store_publishable() { } #[test] -#[should_panic] // TODO: #654 will fix this fn direct_proxy_install_toolchain_not_in_store_forc_plugin() { test_direct_proxy_install_toolchain_not_in_store(Some("forc-client")); } #[test] -#[should_panic] // TODO: #654 will fix this fn direct_proxy_install_toolchain_not_in_store_forc_plugin_external() { test_direct_proxy_install_toolchain_not_in_store(Some("forc-tx")); }