mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
fix(generate-lockfile): hold lock before querying index
This commit is contained in:
parent
5587af7caf
commit
f1c139624f
@ -166,12 +166,17 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Prints lockfile change statuses.
|
||||||
|
///
|
||||||
|
/// This would acquire the package-cache lock, as it may update the index to
|
||||||
|
/// show users latest available versions.
|
||||||
pub fn print_lockfile_changes(
|
pub fn print_lockfile_changes(
|
||||||
gctx: &GlobalContext,
|
gctx: &GlobalContext,
|
||||||
previous_resolve: Option<&Resolve>,
|
previous_resolve: Option<&Resolve>,
|
||||||
resolve: &Resolve,
|
resolve: &Resolve,
|
||||||
registry: &mut PackageRegistry<'_>,
|
registry: &mut PackageRegistry<'_>,
|
||||||
) -> CargoResult<()> {
|
) -> CargoResult<()> {
|
||||||
|
let _lock = gctx.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
|
||||||
if let Some(previous_resolve) = previous_resolve {
|
if let Some(previous_resolve) = previous_resolve {
|
||||||
print_lockfile_sync(gctx, previous_resolve, resolve, registry)
|
print_lockfile_sync(gctx, previous_resolve, resolve, registry)
|
||||||
} else {
|
} else {
|
||||||
|
@ -256,11 +256,6 @@ fn resolve_with_registry<'gctx>(
|
|||||||
false
|
false
|
||||||
};
|
};
|
||||||
if print {
|
if print {
|
||||||
// We only want one Cargo at a time resolving a crate graph since this can
|
|
||||||
// involve a lot of frobbing of the global caches.
|
|
||||||
let _lock = ws
|
|
||||||
.gctx()
|
|
||||||
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
|
|
||||||
ops::print_lockfile_changes(ws.gctx(), prev.as_ref(), &resolve, registry)?;
|
ops::print_lockfile_changes(ws.gctx(), prev.as_ref(), &resolve, registry)?;
|
||||||
}
|
}
|
||||||
Ok(resolve)
|
Ok(resolve)
|
||||||
|
@ -266,11 +266,9 @@ fn generate_lockfile_holds_lock_and_offline() {
|
|||||||
.run();
|
.run();
|
||||||
|
|
||||||
p.cargo("generate-lockfile --offline")
|
p.cargo("generate-lockfile --offline")
|
||||||
.with_status(101)
|
|
||||||
.with_stderr_contains(
|
.with_stderr_contains(
|
||||||
"\
|
"\
|
||||||
[..]thread 'main' panicked[..]
|
[LOCKING] 2 packages
|
||||||
[..]package cache lock is not currently held[..]
|
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.run();
|
.run();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user