From 11a7522ce1b2855dce68766884b80414bd0d847f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 20 Jul 2023 08:51:43 +0200 Subject: [PATCH] additional protection against raciness when cloning in parallel When cloning the index at the same time, as is done by tests, it's possible to discover a newly initialized repository that isn't quite ready yet, causing failures lateron. To prevent that, we have to be sure there is no opening happening while we are cloning. --- src/bare_index.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/bare_index.rs b/src/bare_index.rs index 4df19f3f..6a0a0af7 100644 --- a/src/bare_index.rs +++ b/src/bare_index.rs @@ -144,6 +144,15 @@ impl Index { }); mapping.reduced = open_with_complete_config.clone(); mapping.full = open_with_complete_config.clone(); + + let _lock = gix::lock::Marker::acquire_to_hold_resource( + path.with_extension("crates-index"), + gix::lock::acquire::Fail::AfterDurationWithBackoff( + std::time::Duration::from_secs(60 * 10), + ), + Some(PathBuf::from_iter(Some(std::path::Component::RootDir))), + ) + .map_err(GixError::from)?; let repo = gix::ThreadSafeRepository::discover_opts( &path, gix::discover::upwards::Options::default().apply_environment(), @@ -163,15 +172,6 @@ impl Index { let repo = match repo { Some(repo) => repo, None => { - let _lock = gix::lock::Marker::acquire_to_hold_resource( - path.with_extension("crates-index"), - gix::lock::acquire::Fail::AfterDurationWithBackoff( - std::time::Duration::from_secs(60 * 10), - ), - Some(PathBuf::from_iter(Some(std::path::Component::RootDir))), - ) - .map_err(GixError::from)?; - match gix::open_opts(&path, open_with_complete_config).ok() { None => clone_url(&url, &path)?, Some(repo) => repo,