]> git.proxmox.com Git - proxmox-backup.git/commitdiff
server: remove jobstate: ignore removal error due to file not found
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 1 Jun 2022 14:40:06 +0000 (16:40 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 1 Jun 2022 14:40:09 +0000 (16:40 +0200)
we want to remove lock and state file anyway, so not found is all
right

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/server/jobstate.rs

index dfc5362ab683b846a09a1794390615d7bb8a8e2c..5cd43c84828ed9ad83385f3f956f02575ebb4572 100644 (file)
@@ -112,24 +112,17 @@ where
 pub fn remove_state_file(jobtype: &str, jobname: &str) -> Result<(), Error> {
     let mut path = get_path(jobtype, jobname);
     let _lock = get_lock(&path)?;
-    std::fs::remove_file(&path).map_err(|err| {
-        format_err!(
-            "cannot remove statefile for {} - {}: {}",
-            jobtype,
-            jobname,
-            err
-        )
-    })?;
+    if let Err(err) = std::fs::remove_file(&path) {
+        if err.kind() != std::io::ErrorKind::NotFound {
+            bail!("cannot remove statefile for {jobtype} - {jobname}: {err}");
+        }
+    }
     path.set_extension("lck");
-    // ignore errors
-    let _ = std::fs::remove_file(&path).map_err(|err| {
-        format_err!(
-            "cannot remove lockfile for {} - {}: {}",
-            jobtype,
-            jobname,
-            err
-        )
-    });
+    if let Err(err) = std::fs::remove_file(&path) {
+        if err.kind() != std::io::ErrorKind::NotFound {
+            bail!("cannot remove lockfile for {jobtype} - {jobname}: {err}");
+        }
+    }
     Ok(())
 }