Skip to content

Commit 3952fdb

Browse files
committed
Refactor code and resolve PR comments
1 parent dd654d5 commit 3952fdb

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -546,29 +546,27 @@ where
546546
}
547547
None => {
548548
let version: String = dep.version_req().to_string();
549-
match PackageId::new(dep.package_name(), &version[1..], source.source_id()) {
550-
Ok(pkg_id) => {
551-
if source.is_yanked(pkg_id).unwrap_or(false) {
552-
bail!(
553-
"cannot install package `{}`, it has been yanked from {}",
554-
pkg_id.name(),
555-
pkg_id.source_id()
556-
)
557-
} else {
558-
bail!(
559-
"could not find `{}` in {} with version `{}`",
560-
dep.package_name(),
561-
source.source_id(),
562-
dep.version_req(),
563-
)
564-
}
565-
}
566-
Err(_) => bail!(
549+
let pkg_id;
550+
if dep.version_req().is_exact() {
551+
pkg_id = PackageId::new(dep.package_name(), &version[1..], source.source_id());
552+
} else {
553+
pkg_id = PackageId::new(dep.package_name(), &version[..], source.source_id());
554+
}
555+
let is_yanked =
556+
pkg_id.map_or(false, |pkg_id| source.is_yanked(pkg_id).unwrap_or(false));
557+
if is_yanked {
558+
bail!(
559+
"cannot install package `{}`, it has been yanked from {}",
560+
dep.package_name(),
561+
source.source_id()
562+
)
563+
} else {
564+
bail!(
567565
"could not find `{}` in {} with version `{}`",
568566
dep.package_name(),
569567
source.source_id(),
570568
dep.version_req(),
571-
),
569+
)
572570
}
573571
}
574572
}

tests/testsuite/install.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ use std::io::prelude::*;
55

66
use cargo_test_support::cross_compile;
77
use cargo_test_support::git;
8-
use cargo_test_support::install::{
9-
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
10-
};
11-
use cargo_test_support::paths;
128
use cargo_test_support::registry::{registry_path, registry_url, Package};
139
use cargo_test_support::{
1410
basic_manifest, cargo_process, no_such_file_err_msg, project, symlink_supported, t,
1511
};
1612

13+
use cargo_test_support::install::{
14+
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
15+
};
16+
use cargo_test_support::paths;
17+
1718
fn pkg(name: &str, vers: &str) {
1819
Package::new(name, vers)
1920
.file("src/lib.rs", "")
@@ -1561,6 +1562,9 @@ fn install_yanked_cargo_package() {
15611562
Package::new("baz", "0.0.1").yanked(true).publish();
15621563
cargo_process("install baz --version 0.0.1")
15631564
.with_status(101)
1564-
.with_stderr_contains("error: cannot install package `baz`, it has been yanked from registry `https://github.com/rust-lang/crates.io-index`")
1565+
.with_stderr_contains(
1566+
"error: cannot install package `baz`, it has been yanked from registry \
1567+
`https://github.com/rust-lang/crates.io-index`",
1568+
)
15651569
.run();
15661570
}

tests/testsuite/install_upgrade.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@ fn already_installed_updates_yank_status_on_upgrade() {
800800
cargo_process("install foo --version=1.0.1")
801801
.with_status(101)
802802
.with_stderr_contains(
803-
"error: cannot install package `foo`, it has been yanked from registry `https://github.com/rust-lang/crates.io-index`",
803+
"error: cannot install package `foo`, it has been yanked from registry \
804+
`https://github.com/rust-lang/crates.io-index`",
804805
)
805806
.run();
806807

0 commit comments

Comments
 (0)