diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-02 22:40:59 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-02 22:40:59 +0200 |
commit | 89e193c1ab8184f74b2b40f3822e544d5e0d5163 (patch) | |
tree | dae862e629bd499c3d7f344ebeab938781e913a6 /crates/runner/src/util/unix.rs | |
parent | 1e8875b6437f3b3a1505e25dde8e352d232b09fa (diff) | |
download | rebel-89e193c1ab8184f74b2b40f3822e544d5e0d5163.tar rebel-89e193c1ab8184f74b2b40f3822e544d5e0d5163.zip |
Update dependencies
Diffstat (limited to 'crates/runner/src/util/unix.rs')
-rw-r--r-- | crates/runner/src/util/unix.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/crates/runner/src/util/unix.rs b/crates/runner/src/util/unix.rs index 156e441..08884ec 100644 --- a/crates/runner/src/util/unix.rs +++ b/crates/runner/src/util/unix.rs @@ -1,7 +1,7 @@ use std::{fs::File, os::unix::prelude::*, path::Path}; use nix::{ - fcntl::{self, FcntlArg, FdFlag, OFlag}, + fcntl::{self, FcntlArg, FdFlag, Flock, OFlag}, sched, unistd::Pid, }; @@ -65,7 +65,7 @@ pub fn nproc() -> Result<usize> { Ok(count) } -pub fn lock<P: AsRef<Path>>(path: P, exclusive: bool, blocking: bool) -> Result<File> { +pub fn lock<P: AsRef<Path>>(path: P, exclusive: bool, blocking: bool) -> Result<Flock<File>> { use fcntl::FlockArg::*; if let Some(parent) = path.as_ref().parent() { @@ -80,8 +80,7 @@ pub fn lock<P: AsRef<Path>>(path: P, exclusive: bool, blocking: bool) -> Result< }; let file = fs::create(path.as_ref())?; - fcntl::flock(file.as_raw_fd(), arg) - .with_context(|| format!("flock failed on {:?}", path.as_ref()))?; - - Ok(file) + fcntl::Flock::lock(file, arg) + .map_err(|(_, errno)| errno) + .with_context(|| format!("flock failed on {:?}", path.as_ref())) } |