fix: actually check if lock was acquired

This commit is contained in:
elsirion 2025-03-18 22:44:52 +03:00
parent 2a0dbc27d2
commit 61fd30c810
No known key found for this signature in database
GPG key ID: B3005E571AA314DA

View file

@ -44,7 +44,8 @@ impl FileLock {
/// Note that this operation is blocking, and should not be called in async contexts.
pub fn new_try_exclusive(file: File) -> Result<Self, (File, Option<io::Error>)> {
match FileExt::try_lock_exclusive(&file) {
Ok(_) => Ok(Self::new(file)),
Ok(true) => Ok(Self::new(file)),
Ok(false) => Err((file, None)),
Err(e) if e.raw_os_error() == fs4::lock_contended_error().raw_os_error() => {
Err((file, None))
}
@ -70,7 +71,8 @@ impl FileLock {
/// Note that this operation is blocking, and should not be called in async contexts.
pub fn new_try_shared(file: File) -> Result<Self, (File, Option<io::Error>)> {
match FileExt::try_lock_shared(&file) {
Ok(_) => Ok(Self::new(file)),
Ok(true) => Ok(Self::new(file)),
Ok(false) => Err((file, None)),
Err(e) if e.raw_os_error() == fs4::lock_contended_error().raw_os_error() => {
Err((file, None))
}