From d8ecdcaeec5c63f45d9087df820967486a5ede64 Mon Sep 17 00:00:00 2001 From: elsirion <84478054+elsirion@users.noreply.github.com> Date: Wed, 19 Mar 2025 12:41:51 +0300 Subject: [PATCH] fix: actually check if lock was acquired (#2091) --- crates/fs-lock/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/fs-lock/src/lib.rs b/crates/fs-lock/src/lib.rs index f3c8ac8a..311c72d7 100644 --- a/crates/fs-lock/src/lib.rs +++ b/crates/fs-lock/src/lib.rs @@ -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)> { 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)> { 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)) }