[pbs-devel] [PATCH proxmox-backup 3/8] config: add JobState helper

Dietmar Maurer dietmar at proxmox.com
Mon Aug 3 09:38:08 CEST 2020


suggested cleanups:

diff --git a/src/config/jobstate.rs b/src/config/jobstate.rs
index fb5a8cb..974b8e9 100644
--- a/src/config/jobstate.rs
+++ b/src/config/jobstate.rs
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
 use std::time::Duration;
 
 use serde::{Serialize, Deserialize};
-use anyhow::{bail, Error, format_err};
+use anyhow::{Error, format_err};
 use proxmox::tools::fs::{file_read_optional_string, replace_file, create_path, CreateOptions};
 
 use crate::tools::{epoch_now_u64, open_file_locked};
@@ -48,19 +48,15 @@ where
 {
     let mut path = path.as_ref().to_path_buf();
     path.set_extension("lck");
-    let lock = open_file_locked(path, Duration::new(10, 0))?;
-    Ok(lock)
+    open_file_locked(path, Duration::new(10, 0))
 }
 
 pub fn remove_state_file(jobtype: &str, jobname: &str) -> Result<(), Error> {
     let path = get_path(jobtype, jobname)?;
     let _lock = get_lock(&path)?;
-    match std::fs::remove_file(&path) {
-        Ok(()) => Ok(()),
-        Err(err) => {
-            bail!("cannot remove statefile for {} - {}: {}", jobtype, jobname, err);
-        }
-    }
+    std::fs::remove_file(&path).map_err(|err| {
+        format_err!("cannot remove statefile for {} - {}: {}", jobtype, jobname, err)
+    })
 }

 impl JobState {





More information about the pbs-devel mailing list