From 397f446dcd7a5f38dcd472022fa74201ce888963 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 23 Oct 2023 09:40:19 +0800 Subject: [PATCH 1/2] Add test for installing the same binary twice Signed-off-by: hi-rustin --- tests/testsuite/install.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 0da4a57cc27..aa48c8f48ec 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -57,6 +57,34 @@ fn simple() { assert_has_not_installed_exe(cargo_home(), "foo"); } +#[cargo_test] +fn install_the_same_version_twice() { + pkg("foo", "0.0.1"); + + cargo_process("install foo foo") + .with_stderr( + "\ +[UPDATING] `[..]` index +[DOWNLOADING] crates ... +[DOWNLOADED] foo v0.0.1 (registry [..]) +[INSTALLING] foo v0.0.1 +[COMPILING] foo v0.0.1 +[FINISHED] release [optimized] target(s) in [..] +[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE] +[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`) +[INSTALLING] foo v0.0.1 +[COMPILING] foo v0.0.1 +[FINISHED] release [optimized] target(s) in [..] +[REPLACING] [CWD]/home/.cargo/bin/foo[EXE] +[REPLACED] package `foo v0.0.1` with `foo v0.0.1` (executable `foo[EXE]`) + Summary Successfully installed foo, foo! +[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries +", + ) + .run(); + assert_has_installed_exe(cargo_home(), "foo"); +} + #[cargo_test] fn toolchain() { pkg("foo", "0.0.1"); From 731ae05ae364db7c0df8ad319162cfcd7bd59919 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 23 Oct 2023 09:42:05 +0800 Subject: [PATCH 2/2] Dedup the same version binaries Signed-off-by: hi-rustin --- src/bin/cargo/commands/install.rs | 2 ++ tests/testsuite/install.rs | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 4275aa70075..b51c021f567 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -9,6 +9,7 @@ use cargo::util::IntoUrl; use cargo::util::ToSemver; use cargo::util::VersionReqExt; use cargo::CargoResult; +use itertools::Itertools; use semver::VersionReq; use cargo_util::paths; @@ -119,6 +120,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { .get_many::("crate") .unwrap_or_default() .cloned() + .dedup_by(|x, y| x == y) .map(|(krate, local_version)| resolve_crate(krate, local_version, version)) .collect::>>()?; diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index aa48c8f48ec..fd53b607bf3 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -72,12 +72,6 @@ fn install_the_same_version_twice() { [FINISHED] release [optimized] target(s) in [..] [INSTALLING] [CWD]/home/.cargo/bin/foo[EXE] [INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`) -[INSTALLING] foo v0.0.1 -[COMPILING] foo v0.0.1 -[FINISHED] release [optimized] target(s) in [..] -[REPLACING] [CWD]/home/.cargo/bin/foo[EXE] -[REPLACED] package `foo v0.0.1` with `foo v0.0.1` (executable `foo[EXE]`) - Summary Successfully installed foo, foo! [WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries ", )