flock: a bit of cleanup

This commit is contained in:
Ralf Jung 2024-08-01 11:29:40 +02:00
parent 50d51fb1bf
commit 5af27e4617
3 changed files with 9 additions and 10 deletions

View File

@ -12,6 +12,13 @@
use crate::shims::unix::*;
use crate::*;
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub(crate) enum FlockOp {
SharedLock { nonblocking: bool },
ExclusiveLock { nonblocking: bool },
Unlock,
}
/// Represents an open file descriptor.
pub trait FileDescription: std::fmt::Debug + Any {
fn name(&self) -> &'static str;
@ -567,10 +574,3 @@ fn write(
Ok(Scalar::from_target_isize(this.try_unwrap_io_result(result)?, this))
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub(crate) enum FlockOp {
SharedLock { nonblocking: bool },
ExclusiveLock { nonblocking: bool },
Unlock,
}

View File

@ -198,8 +198,8 @@ fn flock<'tcx>(
let code: u32 = err.raw_os_error().unwrap().try_into().unwrap();
if matches!(code, ERROR_IO_PENDING | ERROR_LOCK_VIOLATION) {
if lock_nb {
// Replace error with a custom WouldBlock error, which later will be
// mapped in the `helpers` module
// The io error mapping does not know about these error codes,
// so we translate it to `WouldBlock` manually.
let desc = format!("LockFileEx wouldblock error: {err}");
err = io::Error::new(io::ErrorKind::WouldBlock, desc);
} else {

View File

@ -1,4 +1,3 @@
// Flock tests are separate since they don't in general work on a Windows host.
//@ignore-target-windows: File handling is not implemented yet
//@compile-flags: -Zmiri-disable-isolation