mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-04 03:00:03 +00:00
fix: actually check if lock was acquired (#2091)
This commit is contained in:
parent
7790943190
commit
d8ecdcaeec
1 changed files with 4 additions and 2 deletions
|
@ -44,7 +44,8 @@ impl FileLock {
|
||||||
/// Note that this operation is blocking, and should not be called in async contexts.
|
/// 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>)> {
|
pub fn new_try_exclusive(file: File) -> Result<Self, (File, Option<io::Error>)> {
|
||||||
match FileExt::try_lock_exclusive(&file) {
|
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(e) if e.raw_os_error() == fs4::lock_contended_error().raw_os_error() => {
|
||||||
Err((file, None))
|
Err((file, None))
|
||||||
}
|
}
|
||||||
|
@ -70,7 +71,8 @@ impl FileLock {
|
||||||
/// Note that this operation is blocking, and should not be called in async contexts.
|
/// 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>)> {
|
pub fn new_try_shared(file: File) -> Result<Self, (File, Option<io::Error>)> {
|
||||||
match FileExt::try_lock_shared(&file) {
|
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(e) if e.raw_os_error() == fs4::lock_contended_error().raw_os_error() => {
|
||||||
Err((file, None))
|
Err((file, None))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue