Skip to content

Commit 384e256

Browse files
committed
Factor out poll_one_package
1 parent 2c9c66d commit 384e256

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/cargo/ops/registry/publish.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ use crate::core::manifest::ManifestMetadata;
2121
use crate::core::resolver::CliFeatures;
2222
use crate::core::Dependency;
2323
use crate::core::Package;
24+
use crate::core::PackageId;
2425
use crate::core::PackageIdSpecQuery;
2526
use crate::core::SourceId;
2627
use crate::core::Workspace;
2728
use crate::ops;
2829
use crate::ops::PackageOpts;
2930
use crate::ops::Packages;
3031
use crate::sources::source::QueryKind;
32+
use crate::sources::source::Source;
3133
use crate::sources::SourceConfigMap;
3234
use crate::sources::CRATES_IO_REGISTRY;
3335
use crate::util::auth;
@@ -189,14 +191,12 @@ fn wait_for_publish(
189191
pkg: &Package,
190192
timeout: Duration,
191193
) -> CargoResult<()> {
192-
let version_req = format!("={}", pkg.version());
193194
let mut source = SourceConfigMap::empty(gctx)?.load(registry_src, &HashSet::new())?;
194195
// Disable the source's built-in progress bars. Repeatedly showing a bunch
195196
// of independent progress bars can be a little confusing. There is an
196197
// overall progress bar managed here.
197198
source.set_quiet(true);
198199
let source_description = source.source_id().to_string();
199-
let query = Dependency::parse(pkg.name(), Some(&version_req), registry_src)?;
200200

201201
let now = std::time::Instant::now();
202202
let sleep_time = Duration::from_secs(1);
@@ -223,16 +223,7 @@ fn wait_for_publish(
223223
// multiple times
224224
gctx.updated_sources().remove(&source.replaced_source_id());
225225
source.invalidate_cache();
226-
let summaries = loop {
227-
// Exact to avoid returning all for path/git
228-
match source.query_vec(&query, QueryKind::Exact) {
229-
std::task::Poll::Ready(res) => {
230-
break res?;
231-
}
232-
std::task::Poll::Pending => source.block_until_ready()?,
233-
}
234-
};
235-
if !summaries.is_empty() {
226+
if poll_one_package(registry_src, &pkg.package_id(), &mut source)? {
236227
break true;
237228
}
238229
}
@@ -262,6 +253,25 @@ fn wait_for_publish(
262253
Ok(())
263254
}
264255

256+
fn poll_one_package(
257+
registry_src: SourceId,
258+
pkg_id: &PackageId,
259+
source: &mut dyn Source,
260+
) -> CargoResult<bool> {
261+
let version_req = format!("={}", pkg_id.version());
262+
let query = Dependency::parse(pkg_id.name(), Some(&version_req), registry_src)?;
263+
let summaries = loop {
264+
// Exact to avoid returning all for path/git
265+
match source.query_vec(&query, QueryKind::Exact) {
266+
std::task::Poll::Ready(res) => {
267+
break res?;
268+
}
269+
std::task::Poll::Pending => source.block_until_ready()?,
270+
}
271+
};
272+
Ok(!summaries.is_empty())
273+
}
274+
265275
fn verify_dependencies(
266276
pkg: &Package,
267277
registry: &Registry,

0 commit comments

Comments
 (0)