From 31dbaf69ab7f9fc9181dba84bcf3a2a4a37471f8 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Wed, 16 Apr 2025 12:49:59 +0200 Subject: [PATCH] garbage collection: fail on ArchiveType::Blob in open index reader Instead of returning a None, fail if the open index reader is called on a blob file. Blobs cannot be read as index anyways and this allows to distinguish cases where the index file cannot be read because vanished. Signed-off-by: Christian Ebner Link: https://lore.proxmox.com/20250416105000.270166-2-c.ebner@proxmox.com --- pbs-datastore/src/datastore.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index aa38e2ac..333f5f8d 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -1031,13 +1031,15 @@ impl DataStore { Ok(list) } - // Similar to open index, but ignore index files with blob or unknown archive type. - // Further, do not fail if file vanished. - fn open_index_reader(&self, absolute_path: &Path) -> Result>, Error> { + // Similar to open index, but return with Ok(None) if index file vanished. + fn open_index_reader( + &self, + absolute_path: &Path, + ) -> Result>, Error> { let archive_type = match ArchiveType::from_path(absolute_path) { - Ok(archive_type) => archive_type, // ignore archives with unknown archive type - Err(_) => return Ok(None), + Ok(ArchiveType::Blob) | Err(_) => bail!("unexpected archive type"), + Ok(archive_type) => archive_type, }; if absolute_path.is_relative() { @@ -1064,7 +1066,7 @@ impl DataStore { .with_context(|| format!("can't open dynamic index '{absolute_path:?}'"))?; Ok(Some(Box::new(reader))) } - ArchiveType::Blob => Ok(None), + ArchiveType::Blob => bail!("unexpected archive type blob"), } } @@ -1151,6 +1153,11 @@ impl DataStore { worker.check_abort()?; worker.fail_on_shutdown()?; + match ArchiveType::from_path(&file) { + Ok(ArchiveType::FixedIndex) | Ok(ArchiveType::DynamicIndex) => (), + Ok(ArchiveType::Blob) | Err(_) => continue, + } + let mut path = snapshot.backup_dir.full_path(); path.push(file);