Skip to content

Commit 57a0f8c

Browse files
committed
Auto merge of #10835 - arlosi:refactor_yanked, r=ehuss
Refactor check_yanked to avoid some duplication Follow up from #10830 r? `@ehuss`
2 parents 6867277 + 8a1f401 commit 57a0f8c

File tree

3 files changed

+22
-45
lines changed

3 files changed

+22
-45
lines changed

src/cargo/ops/cargo_install.rs

+6-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
22
use std::path::{Path, PathBuf};
33
use std::sync::Arc;
4-
use std::task::Poll;
54
use std::{env, fs};
65

76
use crate::core::compiler::{CompileKind, DefaultExecutor, Executor, Freshness, UnitOutput};
@@ -531,44 +530,12 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
531530
// duplicate "Updating", but since `source` is taken by value, then it
532531
// wouldn't be available for `compile_ws`.
533532
let (pkg_set, resolve) = ops::resolve_ws(&self.ws)?;
534-
535-
// Checking the yanked status involves taking a look at the registry and
536-
// maybe updating files, so be sure to lock it here.
537-
let _lock = self.ws.config().acquire_package_cache_lock()?;
538-
539-
let mut sources = pkg_set.sources_mut();
540-
let mut pending: Vec<PackageId> = resolve.iter().collect();
541-
let mut results = Vec::new();
542-
for (_id, source) in sources.sources_mut() {
543-
source.invalidate_cache();
544-
}
545-
while !pending.is_empty() {
546-
pending.retain(|pkg_id| {
547-
if let Some(source) = sources.get_mut(pkg_id.source_id()) {
548-
match source.is_yanked(*pkg_id) {
549-
Poll::Ready(result) => results.push((*pkg_id, result)),
550-
Poll::Pending => return true,
551-
}
552-
}
553-
false
554-
});
555-
for (_id, source) in sources.sources_mut() {
556-
source.block_until_ready()?;
557-
}
558-
}
559-
560-
for (pkg_id, is_yanked) in results {
561-
if is_yanked? {
562-
self.ws.config().shell().warn(format!(
563-
"package `{}` in Cargo.lock is yanked in registry `{}`, \
564-
consider running without --locked",
565-
pkg_id,
566-
pkg_id.source_id().display_registry_name()
567-
))?;
568-
}
569-
}
570-
571-
Ok(())
533+
ops::check_yanked(
534+
self.ws.config(),
535+
&pkg_set,
536+
&resolve,
537+
"consider running without --locked",
538+
)
572539
}
573540
}
574541

src/cargo/ops/cargo_package.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,12 @@ fn build_lock(ws: &Workspace<'_>, orig_pkg: &Package) -> CargoResult<String> {
375375
if let Some(orig_resolve) = orig_resolve {
376376
compare_resolve(config, tmp_ws.current()?, &orig_resolve, &new_resolve)?;
377377
}
378-
check_yanked(config, &pkg_set, &new_resolve)?;
378+
check_yanked(
379+
config,
380+
&pkg_set,
381+
&new_resolve,
382+
"consider updating to a version that is not yanked",
383+
)?;
379384

380385
ops::resolve_to_string(&tmp_ws, &mut new_resolve)
381386
}
@@ -717,7 +722,12 @@ fn compare_resolve(
717722
Ok(())
718723
}
719724

720-
fn check_yanked(config: &Config, pkg_set: &PackageSet<'_>, resolve: &Resolve) -> CargoResult<()> {
725+
pub fn check_yanked(
726+
config: &Config,
727+
pkg_set: &PackageSet<'_>,
728+
resolve: &Resolve,
729+
hint: &str,
730+
) -> CargoResult<()> {
721731
// Checking the yanked status involves taking a look at the registry and
722732
// maybe updating files, so be sure to lock it here.
723733
let _lock = config.acquire_package_cache_lock()?;
@@ -746,10 +756,10 @@ fn check_yanked(config: &Config, pkg_set: &PackageSet<'_>, resolve: &Resolve) ->
746756
for (pkg_id, is_yanked) in results {
747757
if is_yanked? {
748758
config.shell().warn(format!(
749-
"package `{}` in Cargo.lock is yanked in registry `{}`, \
750-
consider updating to a version that is not yanked",
759+
"package `{}` in Cargo.lock is yanked in registry `{}`, {}",
751760
pkg_id,
752-
pkg_id.source_id().display_registry_name()
761+
pkg_id.source_id().display_registry_name(),
762+
hint
753763
))?;
754764
}
755765
}

src/cargo/ops/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub use self::cargo_generate_lockfile::UpdateOptions;
1313
pub use self::cargo_install::{install, install_list};
1414
pub use self::cargo_new::{init, new, NewOptions, VersionControl};
1515
pub use self::cargo_output_metadata::{output_metadata, ExportInfo, OutputMetadataOptions};
16-
pub use self::cargo_package::{package, package_one, PackageOpts};
16+
pub use self::cargo_package::{check_yanked, package, package_one, PackageOpts};
1717
pub use self::cargo_pkgid::pkgid;
1818
pub use self::cargo_read_manifest::{read_package, read_packages};
1919
pub use self::cargo_run::run;

0 commit comments

Comments
 (0)