MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / acquire

Method acquire

atomic-repository/src/repository/projection_effects.rs:1423–1447  ·  view source on GitHub ↗
(git: &GitRepository, attempts: u32)

Source from the content-addressed store, hash-verified

1421
1422impl GitIndexLockGuard {
1423 fn acquire(git: &GitRepository, attempts: u32) -> Result<Option<Self>, RepositoryError> {
1424 let path = git.path().join("index.lock");
1425 for attempt in 0..attempts {
1426 match fs::OpenOptions::new()
1427 .write(true)
1428 .create_new(true)
1429 .open(&path)
1430 {
1431 Ok(_) => return Ok(Some(Self { path })),
1432 Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => {
1433 if attempt + 1 == attempts {
1434 return Ok(None);
1435 }
1436 std::thread::sleep(std::time::Duration::from_millis(25 * (attempt as u64 + 1)));
1437 }
1438 Err(error) => {
1439 return Err(git_map(format!(
1440 "cannot create the Git index lock '{}': {error}",
1441 path.display()
1442 )))
1443 }
1444 }
1445 }
1446 Ok(None)
1447 }
1448}
1449
1450impl Drop for GitIndexLockGuard {

Callers

nothing calls this directly

Calls 5

git_mapFunction · 0.70
pathMethod · 0.45
openMethod · 0.45
writeMethod · 0.45
kindMethod · 0.45

Tested by

no test coverage detected