From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] rest-server: cleanup_old_tasks: improve error handling
Date: Fri, 25 Mar 2022 13:38:16 +0100 [thread overview]
Message-ID: <20220325123816.3865356-1-d.csapak@proxmox.com> (raw)
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@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
next reply other threads:[~2022-03-25 12:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-25 12:38 Dominik Csapak [this message]
2022-03-28 6:30 ` Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220325123816.3865356-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.