Skip to content

Commit 0aedda2

Browse files
committed
Auto merge of #8565 - pawanbisht62:master, r=ehuss
cargo install with specific yanked version gives confusing "not found" error Resolves #8171
2 parents f84a627 + 81687e7 commit 0aedda2

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,29 @@ where
544544
let pkg = Box::new(source).download_now(pkgid, config)?;
545545
Ok(pkg)
546546
}
547-
None => bail!(
548-
"could not find `{}` in {} with version `{}`",
549-
dep.package_name(),
550-
source.source_id(),
551-
dep.version_req(),
552-
),
547+
None => {
548+
let is_yanked: bool = if dep.version_req().is_exact() {
549+
let version: String = dep.version_req().to_string();
550+
PackageId::new(dep.package_name(), &version[1..], source.source_id())
551+
.map_or(false, |pkg_id| source.is_yanked(pkg_id).unwrap_or(false))
552+
} else {
553+
false
554+
};
555+
if is_yanked {
556+
bail!(
557+
"cannot install package `{}`, it has been yanked from {}",
558+
dep.package_name(),
559+
source.source_id()
560+
)
561+
} else {
562+
bail!(
563+
"could not find `{}` in {} with version `{}`",
564+
dep.package_name(),
565+
source.source_id(),
566+
dep.version_req(),
567+
)
568+
}
569+
}
553570
}
554571
}
555572

tests/testsuite/install.rs

Lines changed: 17 additions & 4 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", "")
@@ -1555,3 +1556,15 @@ fn install_git_with_symlink_home() {
15551556
)
15561557
.run();
15571558
}
1559+
1560+
#[cargo_test]
1561+
fn install_yanked_cargo_package() {
1562+
Package::new("baz", "0.0.1").yanked(true).publish();
1563+
cargo_process("install baz --version 0.0.1")
1564+
.with_status(101)
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+
)
1569+
.run();
1570+
}

tests/testsuite/install_upgrade.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,11 +799,9 @@ fn already_installed_updates_yank_status_on_upgrade() {
799799

800800
cargo_process("install foo --version=1.0.1")
801801
.with_status(101)
802-
.with_stderr(
803-
"\
804-
[UPDATING] `[..]` index
805-
[ERROR] could not find `foo` in registry `[..]` with version `=1.0.1`
806-
",
802+
.with_stderr_contains(
803+
"error: cannot install package `foo`, it has been yanked from registry \
804+
`https://github.com/rust-lang/crates.io-index`",
807805
)
808806
.run();
809807

0 commit comments

Comments
 (0)