mirror of
https://github.com/rust-lang/cargo
synced 2024-10-04 14:59:23 +00:00
Refactor code and resolve PR comments
This commit is contained in:
parent
dd654d5576
commit
3952fdb223
|
@ -546,29 +546,27 @@ where
|
|||
}
|
||||
None => {
|
||||
let version: String = dep.version_req().to_string();
|
||||
match PackageId::new(dep.package_name(), &version[1..], source.source_id()) {
|
||||
Ok(pkg_id) => {
|
||||
if source.is_yanked(pkg_id).unwrap_or(false) {
|
||||
bail!(
|
||||
"cannot install package `{}`, it has been yanked from {}",
|
||||
pkg_id.name(),
|
||||
pkg_id.source_id()
|
||||
)
|
||||
} else {
|
||||
bail!(
|
||||
"could not find `{}` in {} with version `{}`",
|
||||
dep.package_name(),
|
||||
source.source_id(),
|
||||
dep.version_req(),
|
||||
)
|
||||
}
|
||||
}
|
||||
Err(_) => bail!(
|
||||
let pkg_id;
|
||||
if dep.version_req().is_exact() {
|
||||
pkg_id = PackageId::new(dep.package_name(), &version[1..], source.source_id());
|
||||
} else {
|
||||
pkg_id = PackageId::new(dep.package_name(), &version[..], source.source_id());
|
||||
}
|
||||
let is_yanked =
|
||||
pkg_id.map_or(false, |pkg_id| source.is_yanked(pkg_id).unwrap_or(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(),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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", "")
|
||||
|
@ -1561,6 +1562,9 @@ 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`")
|
||||
.with_stderr_contains(
|
||||
"error: cannot install package `baz`, it has been yanked from registry \
|
||||
`https://github.com/rust-lang/crates.io-index`",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
|
|
@ -800,7 +800,8 @@ fn already_installed_updates_yank_status_on_upgrade() {
|
|||
cargo_process("install foo --version=1.0.1")
|
||||
.with_status(101)
|
||||
.with_stderr_contains(
|
||||
"error: cannot install package `foo`, it has been yanked from registry `https://github.com/rust-lang/crates.io-index`",
|
||||
"error: cannot install package `foo`, it has been yanked from registry \
|
||||
`https://github.com/rust-lang/crates.io-index`",
|
||||
)
|
||||
.run();
|
||||
|
||||
|
|
Loading…
Reference in a new issue