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

Function is_lock_contended

atomic-repository/src/repository/materialize.rs:30–34  ·  view source on GitHub ↗

True if a `try_lock*` error means the lock is currently held by someone else (as opposed to a genuine I/O failure). On Unix a contended non-blocking lock surfaces as `WouldBlock`, but on Windows the OS returns `ERROR_LOCK_VIOLATION` (code 33), which maps to `ErrorKind::Uncategorized` rather than `WouldBlock`. Comparing the raw OS error against `fs2::lock_contended_error()` handles both platforms.

(e: &std::io::Error)

Source from the content-addressed store, hash-verified

28/// `ErrorKind::Uncategorized` rather than `WouldBlock`. Comparing the raw OS
29/// error against `fs2::lock_contended_error()` handles both platforms.
30pub(crate) fn is_lock_contended(e: &std::io::Error) -> bool {
31 e.kind() == std::io::ErrorKind::WouldBlock
32 || (e.raw_os_error().is_some()
33 && e.raw_os_error() == fs2::lock_contended_error().raw_os_error())
34}
35
36impl Repository {
37 /// Return the first working-copy file that still contains an unresolved

Callers 1

Calls 1

kindMethod · 0.45

Tested by

no test coverage detected