Skip to content

Commit a6aca5f

Browse files
committed
Fix duplicate updating messages when using alt registries by reusing the RegistrySource.
1 parent ba03f16 commit a6aca5f

File tree

7 files changed

+18
-22
lines changed

7 files changed

+18
-22
lines changed

src/cargo/ops/registry/login.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn registry_login(
3434
false,
3535
None,
3636
) {
37-
Ok(registry) => Some(format!("{}/me", registry.host())),
37+
Ok((registry, _)) => Some(format!("{}/me", registry.host())),
3838
Err(e) if e.is::<AuthorizationError>() => e
3939
.downcast::<AuthorizationError>()
4040
.unwrap()

src/cargo/ops/registry/mod.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ impl RegistryCredentialConfig {
118118
/// `registry`, or `index` are set, then uses `crates-io`.
119119
/// * `force_update`: If `true`, forces the index to be updated.
120120
/// * `token_required`: If `true`, the token will be set.
121-
fn registry(
122-
gctx: &GlobalContext,
121+
fn registry<'gctx>(
122+
gctx: &'gctx GlobalContext,
123123
source_ids: &RegistrySourceIds,
124124
token_from_cmdline: Option<Secret<&str>>,
125125
reg_or_index: Option<&RegistryOrIndex>,
126126
force_update: bool,
127127
token_required: Option<Operation<'_>>,
128-
) -> CargoResult<Registry> {
128+
) -> CargoResult<(Registry, RegistrySource<'gctx>)> {
129129
let is_index = reg_or_index.map(|v| v.is_index()).unwrap_or_default();
130130
if is_index && token_required.is_some() && token_from_cmdline.is_none() {
131131
bail!("command-line argument --index requires --token to be specified");
@@ -134,9 +134,9 @@ fn registry(
134134
auth::cache_token_from_commandline(gctx, &source_ids.original, token);
135135
}
136136

137+
let mut src = RegistrySource::remote(source_ids.replacement, &HashSet::new(), gctx)?;
137138
let cfg = {
138139
let _lock = gctx.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
139-
let mut src = RegistrySource::remote(source_ids.replacement, &HashSet::new(), gctx)?;
140140
// Only update the index if `force_update` is set.
141141
if force_update {
142142
src.invalidate_cache()
@@ -168,11 +168,9 @@ fn registry(
168168
None
169169
};
170170
let handle = http_handle(gctx)?;
171-
Ok(Registry::new_handle(
172-
api_host,
173-
token,
174-
handle,
175-
cfg.auth_required,
171+
Ok((
172+
Registry::new_handle(api_host, token, handle, cfg.auth_required),
173+
src,
176174
))
177175
}
178176

src/cargo/ops/registry/owner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn modify_owners(gctx: &GlobalContext, opts: &OwnersOptions) -> CargoResult<
3636

3737
let operation = Operation::Owners { name: &name };
3838
let source_ids = super::get_source_id(gctx, opts.reg_or_index.as_ref())?;
39-
let mut registry = super::registry(
39+
let (mut registry, _) = super::registry(
4040
gctx,
4141
&source_ids,
4242
opts.token.as_ref().map(Secret::as_deref),

src/cargo/ops/registry/publish.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::ops;
2828
use crate::ops::PackageOpts;
2929
use crate::ops::Packages;
3030
use crate::sources::source::QueryKind;
31+
use crate::sources::source::Source;
3132
use crate::sources::SourceConfigMap;
3233
use crate::sources::CRATES_IO_REGISTRY;
3334
use crate::util::auth;
@@ -129,7 +130,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
129130
val => val,
130131
};
131132
let source_ids = super::get_source_id(opts.gctx, reg_or_index.as_ref())?;
132-
let mut registry = super::registry(
133+
let (mut registry, mut source) = super::registry(
133134
opts.gctx,
134135
&source_ids,
135136
opts.token.as_ref().map(Secret::as_deref),
@@ -141,9 +142,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
141142

142143
// Bail before packaging and uploading if same version already exists in the registry
143144

144-
let mut source = SourceConfigMap::empty(opts.gctx)?.load(reg_ids.original, &HashSet::new())?;
145-
146-
let query = Dependency::parse(pkg.name(), Some(&ver), reg_ids.original)?;
145+
let query = Dependency::parse(pkg.name(), Some(&ver), source_ids.replacement)?;
147146

148147
let _lock = opts
149148
.gctx

src/cargo/ops/registry/search.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn search(
2121
limit: u32,
2222
) -> CargoResult<()> {
2323
let source_ids = super::get_source_id(gctx, reg_or_index.as_ref())?;
24-
let mut registry =
24+
let (mut registry, _) =
2525
super::registry(gctx, &source_ids, None, reg_or_index.as_ref(), false, None)?;
2626
let (crates, total_crates) = registry.search(query, limit).with_context(|| {
2727
format!(

src/cargo/ops/registry/yank.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn yank(
4747
}
4848
};
4949
let source_ids = super::get_source_id(gctx, reg_or_index.as_ref())?;
50-
let mut registry = super::registry(
50+
let (mut registry, _) = super::registry(
5151
gctx,
5252
&source_ids,
5353
token.as_ref().map(Secret::as_deref),

tests/testsuite/publish.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,11 @@ fn duplicate_version() {
169169

170170
p.cargo("publish")
171171
.replace_crates_io(registry_dupl.index_url())
172-
.with_stderr(
173-
"\
172+
.with_stderr_data(str![[r#"
174173
[UPDATING] crates.io index
175-
error: crate foo already has version 0.0.1. Aborting publish.
176-
",
177-
)
174+
[ERROR] crate foo already has version 0.0.1. Aborting publish.
175+
176+
"#]])
178177
.with_status(101)
179178
.run();
180179
}

0 commit comments

Comments
 (0)