summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-08-18 14:57:10 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-08-18 15:40:40 +0200
commit17d1ce7a45b21d7dadfbf9d7a80e05f1b26d459d (patch)
tree6e8f1fbcef3599b3b8116fc47d3c5d98483cd05a
parent3ab8c14af3c5e46f885b2a89b8d8d45a15311b9e (diff)
Refactor for readability
This patch refactors `check_another_instance_is_not_running()` for readability. Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r--crates/common/flockfile/src/unix.rs23
1 files 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<Flockfile, FlockfileError> {
- 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)]