Skip to content

Commit

Permalink
Auto merge of #8565 - pawanbisht62:master, r=ehuss
Browse files Browse the repository at this point in the history
cargo install with specific yanked version gives confusing "not found" error

Resolves #8171
  • Loading branch information
bors committed Aug 5, 2020
2 parents f84a627 + 81687e7 commit 0aedda2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
29 changes: 23 additions & 6 deletions src/cargo/ops/common_for_install_and_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,29 @@ where
let pkg = Box::new(source).download_now(pkgid, config)?;
Ok(pkg)
}
None => bail!(
"could not find `{}` in {} with version `{}`",
dep.package_name(),
source.source_id(),
dep.version_req(),
),
None => {
let is_yanked: bool = if dep.version_req().is_exact() {
let version: String = dep.version_req().to_string();
PackageId::new(dep.package_name(), &version[1..], source.source_id())
.map_or(false, |pkg_id| source.is_yanked(pkg_id).unwrap_or(false))
} else {
false
};
if is_yanked {
bail!(
"cannot install package `{}`, it has been yanked from {}",
dep.package_name(),
source.source_id()
)
} else {
bail!(
"could not find `{}` in {} with version `{}`",
dep.package_name(),
source.source_id(),
dep.version_req(),
)
}
}
}
}

Expand Down
21 changes: 17 additions & 4 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ use std::io::prelude::*;

use cargo_test_support::cross_compile;
use cargo_test_support::git;
use cargo_test_support::install::{
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
};
use cargo_test_support::paths;
use cargo_test_support::registry::{registry_path, registry_url, Package};
use cargo_test_support::{
basic_manifest, cargo_process, no_such_file_err_msg, project, symlink_supported, t,
};

use cargo_test_support::install::{
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
};
use cargo_test_support::paths;

fn pkg(name: &str, vers: &str) {
Package::new(name, vers)
.file("src/lib.rs", "")
Expand Down Expand Up @@ -1555,3 +1556,15 @@ fn install_git_with_symlink_home() {
)
.run();
}

#[cargo_test]
fn install_yanked_cargo_package() {
Package::new("baz", "0.0.1").yanked(true).publish();
cargo_process("install baz --version 0.0.1")
.with_status(101)
.with_stderr_contains(
"error: cannot install package `baz`, it has been yanked from registry \
`https://github.com/rust-lang/crates.io-index`",
)
.run();
}
8 changes: 3 additions & 5 deletions tests/testsuite/install_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,9 @@ fn already_installed_updates_yank_status_on_upgrade() {

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

Expand Down

0 comments on commit 0aedda2

Please sign in to comment.