simplify open_file_locked

This commit is contained in:
Dietmar Maurer 2020-09-28 09:16:53 +02:00
parent 5440c65787
commit f9763e12f9

View File

@ -514,19 +514,9 @@ pub fn lock_file<F: AsRawFd>(
Ok(())
}
/// Open or create a lock file (append mode). Then try to
/// acquire a shared lock using `lock_file()`.
pub fn open_file_locked_shared<P: AsRef<Path>>(path: P, timeout: Duration) -> Result<File, Error> {
open_file_locked_impl(path, timeout, false)
}
/// Open or create a lock file (append mode). Then try to
/// acquire a lock using `lock_file()`.
pub fn open_file_locked<P: AsRef<Path>>(path: P, timeout: Duration) -> Result<File, Error> {
open_file_locked_impl(path, timeout, true)
}
fn open_file_locked_impl<P: AsRef<Path>>(path: P, timeout: Duration, exclusive: bool) -> Result<File, Error> {
pub fn open_file_locked<P: AsRef<Path>>(path: P, timeout: Duration, exclusive: bool) -> Result<File, Error> {
let path = path.as_ref();
let mut file = match OpenOptions::new().create(true).append(true).open(path) {