From f2a57b587f521726c450d461c3edb8b637fa6ac8 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Wed, 4 Oct 2023 14:24:18 +0200 Subject: [PATCH] On cleanup treat notfound as ok This means it is already gone. Probably a parallel run has deleted it. --- src/numbered_dir.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/numbered_dir.rs b/src/numbered_dir.rs index 0924c10..b2e2ea3 100644 --- a/src/numbered_dir.rs +++ b/src/numbered_dir.rs @@ -1,5 +1,6 @@ //! The [`NumberedDir`] type and supporting code. +use std::io::ErrorKind; use std::num::NonZeroU8; use std::path::{Path, PathBuf}; use std::{fs, io}; @@ -137,8 +138,14 @@ fn remove_obsolete_dirs(dir: impl AsRef, base: &str, current: u16, keep: u || (oldest_to_keep < oldest_to_delete && (numdir.number < oldest_to_keep || numdir.number >= oldest_to_delete)) { - fs::remove_dir_all(numdir.path()) - .with_context(|| format!("Failed to remove {}", numdir.path().display()))?; + match fs::remove_dir_all(numdir.path()) { + Ok(_) => (), + Err(err) if err.kind() == ErrorKind::NotFound => (), + Err(err) => { + return Err(err) + .with_context(|| format!("Failed to remove {}", numdir.path().display())) + } + } } }