Skip to content

Commit

Permalink
Fix duplicate updating messages when using alt registries by reusing …
Browse files Browse the repository at this point in the history
…the RegistrySource.
  • Loading branch information
torhovland committed Aug 1, 2024
1 parent 3baf514 commit ef215c7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/cargo/ops/registry/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn registry_login(
let source_ids = get_source_id(gctx, reg_or_index)?;

let login_url = match registry(gctx, token_from_cmdline.clone(), reg_or_index, false, None) {
Ok((registry, _)) => Some(format!("{}/me", registry.host())),
Ok((registry, _, _)) => Some(format!("{}/me", registry.host())),
Err(e) if e.is::<AuthorizationError>() => e
.downcast::<AuthorizationError>()
.unwrap()
Expand Down
9 changes: 5 additions & 4 deletions src/cargo/ops/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ impl RegistryCredentialConfig {
/// `registry`, or `index` are set, then uses `crates-io`.
/// * `force_update`: If `true`, forces the index to be updated.
/// * `token_required`: If `true`, the token will be set.
fn registry(
gctx: &GlobalContext,
fn registry<'gctx>(
gctx: &'gctx GlobalContext,
token_from_cmdline: Option<Secret<&str>>,
reg_or_index: Option<&RegistryOrIndex>,
force_update: bool,
token_required: Option<Operation<'_>>,
) -> CargoResult<(Registry, RegistrySourceIds)> {
) -> CargoResult<(Registry, RegistrySourceIds, RegistrySource<'gctx>)> {
let source_ids = get_source_id(gctx, reg_or_index)?;

let is_index = reg_or_index.map(|v| v.is_index()).unwrap_or_default();
Expand All @@ -131,9 +131,9 @@ fn registry(
auth::cache_token_from_commandline(gctx, &source_ids.original, token);
}

let mut src = RegistrySource::remote(source_ids.replacement, &HashSet::new(), gctx)?;
let cfg = {
let _lock = gctx.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
let mut src = RegistrySource::remote(source_ids.replacement, &HashSet::new(), gctx)?;
// Only update the index if `force_update` is set.
if force_update {
src.invalidate_cache()
Expand Down Expand Up @@ -168,6 +168,7 @@ fn registry(
Ok((
Registry::new_handle(api_host, token, handle, cfg.auth_required),
source_ids,
src,
))
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/registry/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn modify_owners(gctx: &GlobalContext, opts: &OwnersOptions) -> CargoResult<

let operation = Operation::Owners { name: &name };

let (mut registry, _) = super::registry(
let (mut registry, _, _) = super::registry(
gctx,
opts.token.as_ref().map(Secret::as_deref),
opts.reg_or_index.as_ref(),
Expand Down
7 changes: 3 additions & 4 deletions src/cargo/ops/registry/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::ops;
use crate::ops::PackageOpts;
use crate::ops::Packages;
use crate::sources::source::QueryKind;
use crate::sources::source::Source;
use crate::sources::SourceConfigMap;
use crate::sources::CRATES_IO_REGISTRY;
use crate::util::auth;
Expand Down Expand Up @@ -127,7 +128,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
}
val => val,
};
let (mut registry, reg_ids) = super::registry(
let (mut registry, reg_ids, mut source) = super::registry(
opts.gctx,
opts.token.as_ref().map(Secret::as_deref),
reg_or_index.as_ref(),
Expand All @@ -138,9 +139,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {

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

let mut source = SourceConfigMap::empty(opts.gctx)?.load(reg_ids.original, &HashSet::new())?;

let query = Dependency::parse(pkg.name(), Some(&ver), reg_ids.original)?;
let query = Dependency::parse(pkg.name(), Some(&ver), reg_ids.replacement)?;

let _lock = opts
.gctx
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/registry/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn search(
reg_or_index: Option<RegistryOrIndex>,
limit: u32,
) -> CargoResult<()> {
let (mut registry, source_ids) =
let (mut registry, source_ids, _) =
super::registry(gctx, None, reg_or_index.as_ref(), false, None)?;
let (crates, total_crates) = registry.search(query, limit).with_context(|| {
format!(
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/registry/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn yank(
}
};

let (mut registry, _) = super::registry(
let (mut registry, _, _) = super::registry(
gctx,
token.as_ref().map(Secret::as_deref),
reg_or_index.as_ref(),
Expand Down

0 comments on commit ef215c7

Please sign in to comment.