From 2d81f7b0c0bc94544a5f746a1aad8cf008afc28d Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Fri, 2 Oct 2020 15:20:10 +0200 Subject: [PATCH] task archive rotation: better handle non-existing archive if the archive file does not exist yet, we cannot rotate it, but it's not actually an error, so just return Ok(false) to indicate no rotation took place Signed-off-by: Dominik Csapak --- src/server/worker_task.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server/worker_task.rs b/src/server/worker_task.rs index b2e2abd5..409e7b49 100644 --- a/src/server/worker_task.rs +++ b/src/server/worker_task.rs @@ -345,7 +345,12 @@ fn lock_task_list_files(exclusive: bool) -> Result { pub fn rotate_task_log_archive(size_threshold: u64, compress: bool, max_files: Option) -> Result { let _lock = lock_task_list_files(true)?; let path = Path::new(PROXMOX_BACKUP_ARCHIVE_TASK_FN); - let metadata = path.metadata()?; + let metadata = match path.metadata() { + Ok(metadata) => metadata, + Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(false), + Err(err) => bail!("unable to open task archive - {}", err), + }; + if metadata.len() > size_threshold { let mut logrotate = LogRotate::new(PROXMOX_BACKUP_ARCHIVE_TASK_FN, compress).ok_or_else(|| format_err!("could not get archive file names"))?; let backup_user = crate::backup::backup_user()?;