Skip to content

Commit

Permalink
additional protection against raciness when cloning in parallel
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Byron committed Jul 20, 2023
1 parent 52526a1 commit 9f09f47
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/bare_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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(),
Expand All @@ -106,15 +115,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,
Expand Down

0 comments on commit 9f09f47

Please sign in to comment.