summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-07-26 11:18:50 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-08-30 10:03:21 +0200
commit7ddc423d8961efa3acc443bb8deb5828e08201fa (patch)
tree9aeab097e6f4b2b2d0047acaed40e5bcf27e4f2a
parent53c75cb81ec4551fde6dab3e26ef55ff6cd7e7f2 (diff)
Replace match with function chaining
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r--crates/common/flockfile/src/unix.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/crates/common/flockfile/src/unix.rs b/crates/common/flockfile/src/unix.rs
index ce0e29f0..c3cfebe0 100644
--- a/crates/common/flockfile/src/unix.rs
+++ b/crates/common/flockfile/src/unix.rs
@@ -44,24 +44,22 @@ impl Flockfile {
///
pub fn new_lock(path: impl AsRef<Path>) -> Result<Flockfile, FlockfileError> {
let path = PathBuf::new().join(path);
- let file = match OpenOptions::new()
+ let file = OpenOptions::new()
.create(true)
.read(true)
.write(true)
.open(&path)
- {
- Ok(file) => file,
- Err(err) => {
- return Err(FlockfileError::FromIo { path, source: err });
- }
- };
-
- match flock(file.as_raw_fd(), FlockArg::LockExclusiveNonblock) {
- Ok(()) => (),
- Err(err) => {
- return Err(FlockfileError::FromNix { path, source: err });
+ .map_err(|err| FlockfileError::FromIo {
+ path: path.clone(),
+ source: err,
+ })?;
+
+ flock(file.as_raw_fd(), FlockArg::LockExclusiveNonblock).map_err(|err| {
+ FlockfileError::FromNix {
+ path: path.clone(),
+ source: err,
}
- };
+ })?;
info!(r#"Lockfile created {:?}"#, &path);
Ok(Flockfile {