From 17d1ce7a45b21d7dadfbf9d7a80e05f1b26d459d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 18 Aug 2022 14:57:10 +0200 Subject: Refactor for readability This patch refactors `check_another_instance_is_not_running()` for readability. Signed-off-by: Matthias Beyer --- crates/common/flockfile/src/unix.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/common/flockfile/src/unix.rs b/crates/common/flockfile/src/unix.rs index 79fb71e4..dc9a8d39 100644 --- a/crates/common/flockfile/src/unix.rs +++ b/crates/common/flockfile/src/unix.rs @@ -110,20 +110,15 @@ pub fn check_another_instance_is_not_running( app_name: &str, run_dir: &Path, ) -> Result { - match Flockfile::new_lock( - run_dir - .join(format!("{}{}.lock", LOCK_CHILD_DIRECTORY, app_name)) - .as_path(), - ) { - Ok(file) => Ok(file), - Err(err) => match &err { - FlockfileError::FromIo { path, .. } | FlockfileError::FromNix { path, .. } => { - error!("Another instance of {} is running.", app_name); - error!("Lock file path: {}", path.as_path().to_str().unwrap()); - Err(err) - } - }, - } + let lock_path = run_dir.join(format!("{}{}.lock", LOCK_CHILD_DIRECTORY, app_name)); + + Flockfile::new_lock(lock_path.as_path()).map_err(|err| match &err { + FlockfileError::FromIo { path, .. } | FlockfileError::FromNix { path, .. } => { + error!("Another instance of {} is running.", app_name); + error!("Lock file path: {}", path.as_path().to_str().unwrap()); + err + } + }) } #[cfg(test)] -- cgit v1.2.3