-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
95 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,7 @@ pub(crate) fn emulate_freebsd() -> bool { | |
} | ||
} | ||
} | ||
|
||
pub(crate) fn flocking() -> bool { | ||
emulate_freebsd() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//! Implement file locking for systems that lack open file description segment locking but have flock. | ||
pub use nix::fcntl::FlockArg; | ||
pub use nix::fcntl::FlockArg::*; | ||
|
||
use super::*; | ||
|
||
pub trait Flock { | ||
fn flock(&self, arg: FlockArg) -> io::Result<bool>; | ||
} | ||
|
||
impl Flock for File { | ||
/// Locks a segment that spans the maximum possible range of offsets. | ||
fn flock(&self, arg: FlockArg) -> io::Result<bool> { | ||
match nix::fcntl::flock(self.as_raw_fd(), arg) { | ||
Ok(()) => Ok(true), | ||
Err(errno) if errno == nix::Error::EWOULDBLOCK => Ok(false), | ||
Err(errno) => Err(std::io::Error::from_raw_os_error(errno as i32)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::fs::File; | ||
use std::io; | ||
|
||
use nix::fcntl::FlockArg; | ||
|
||
use crate::sys::{FileLocking, Flock}; | ||
|
||
impl FileLocking for File { | ||
fn trim_exclusive_lock_left(&self, _old_left: u64, _new_left: u64) -> io::Result<bool> { | ||
Ok(true) | ||
} | ||
|
||
fn lock_segment(&self, arg: FlockArg, _len: Option<u64>, _offset: u64) -> io::Result<bool> { | ||
self.lock_max_segment(arg) | ||
} | ||
|
||
fn lock_max_segment(&self, arg: FlockArg) -> io::Result<bool> { | ||
self.flock(arg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters