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 <c.ebner@proxmox.com>
Link: https://lore.proxmox.com/20250416105000.270166-2-c.ebner@proxmox.com
This commit is contained in:
Christian Ebner 2025-04-16 12:49:59 +02:00 committed by Thomas Lamprecht
parent af5ff86a26
commit 31dbaf69ab

View File

@ -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<Option<Box<dyn IndexFile>>, Error> {
// Similar to open index, but return with Ok(None) if index file vanished.
fn open_index_reader(
&self,
absolute_path: &Path,
) -> Result<Option<Box<dyn IndexFile>>, 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);