[pbs-devel] [PATCH proxmox-backup] rest-server: cleanup_old_tasks: improve error handling

Dominik Csapak d.csapak at proxmox.com
Fri Mar 25 13:38:16 CET 2022


by not bubbling up most errors, and continuing on. this avoids that we
stop cleaning up because e.g. one directory was missing.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 proxmox-rest-server/src/worker_task.rs | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs
index 643e1872..619b8e9d 100644
--- a/proxmox-rest-server/src/worker_task.rs
+++ b/proxmox-rest-server/src/worker_task.rs
@@ -270,18 +270,33 @@ pub fn cleanup_old_tasks(compressed: bool) -> Result<(), Error> {
         for i in 0..256 {
             let mut path = setup.taskdir.clone();
             path.push(format!("{:02X}", i));
-            for file in std::fs::read_dir(path)? {
-                let file = file?;
+            let files = match std::fs::read_dir(path) {
+                Ok(files) => files,
+                Err(_) => continue, // does not exist or no permissions
+            };
+            for file in files {
+                let file = match file {
+                    Ok(file) => file,
+                    Err(err) => {
+                        log::error!("task cleanup: could not check some file in {}: {}", i, err);
+                        continue;
+                    }
+                };
                 let path = file.path();
 
-                let modified = get_modified(file)
-                    .map_err(|err| format_err!("error getting mtime for {:?}: {}", path, err))?;
+                let modified = match get_modified(file) {
+                    Ok(modified) => modified,
+                    Err(err) => {
+                        log::error!("task cleanup: error getting mtime for {:?}: {}", path, err);
+                        continue;
+                    }
+                };
 
                 if modified < cutoff_time {
                     match std::fs::remove_file(path) {
                         Ok(()) => {},
                         Err(err) if err.kind() == std::io::ErrorKind::NotFound => {},
-                        Err(err) => bail!("could not remove file: {}", err),
+                        Err(err) => log::error!("task cleanup: could not remove file: {}", err),
                     }
                 }
             }
-- 
2.30.2





More information about the pbs-devel mailing list