From: Thomas Lamprecht Date: Sun, 24 Apr 2022 17:09:38 +0000 (+0200) Subject: datastore: move blob loading into BackupDir impl and adapt call sites X-Git-Tag: v2.2.1~262 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=1eef52c206e4771035b35622266ca95fb5b85c45;p=proxmox-backup.git datastore: move blob loading into BackupDir impl and adapt call sites data blobs can only appear in a BackupDir (snapshot) in the backup hierachy, so makes more sense that it lives in there. As it wasn't widely used anyway it's easy to move the single non-package call site over to the new one directly and drop the implementation from Datastore completely. Signed-off-by: Thomas Lamprecht --- diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs index e5bb7c52..2f1eaa6f 100644 --- a/pbs-datastore/src/backup_info.rs +++ b/pbs-datastore/src/backup_info.rs @@ -11,7 +11,7 @@ use pbs_api_types::{BackupType, GroupFilter, BACKUP_DATE_REGEX, BACKUP_FILE_REGE use pbs_config::{open_backup_lockfile, BackupLockGuard}; use crate::manifest::{MANIFEST_BLOB_NAME, MANIFEST_LOCK_NAME}; -use crate::DataStore; +use crate::{DataStore, DataBlob}; /// BackupGroup is a directory containing a list of BackupDir #[derive(Clone)] @@ -345,6 +345,18 @@ impl BackupDir { proxmox_time::epoch_to_rfc3339_utc(backup_time) } + /// load a `DataBlob` from this snapshot's backup dir. + pub fn load_blob(&self, filename: &str) -> Result { + let mut path = self.full_path(); + path.push(filename); + + proxmox_lang::try_block!({ + let mut file = std::fs::File::open(&path)?; + DataBlob::load_from_reader(&mut file) + }) + .map_err(|err| format_err!("unable to load blob '{:?}' - {}", path, err)) + } + /// Returns the filename to lock a manifest /// /// Also creates the basedir. The lockfile is located in diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index 0ef7fe52..6df23c52 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -913,17 +913,6 @@ impl DataStore { self.inner.chunk_store.insert_chunk(chunk, digest) } - pub fn load_blob(&self, backup_dir: &BackupDir, filename: &str) -> Result { - let mut path = backup_dir.full_path(); - path.push(filename); - - proxmox_lang::try_block!({ - let mut file = std::fs::File::open(&path)?; - DataBlob::load_from_reader(&mut file) - }) - .map_err(|err| format_err!("unable to load blob '{:?}' - {}", path, err)) - } - pub fn stat_chunk(&self, digest: &[u8; 32]) -> Result { let (chunk_path, _digest_str) = self.inner.chunk_store.chunk_path(digest); std::fs::metadata(chunk_path).map_err(Error::from) @@ -948,7 +937,7 @@ impl DataStore { /// Load the manifest without a lock. Must not be written back. pub fn load_manifest(&self, backup_dir: &BackupDir) -> Result<(BackupManifest, u64), Error> { - let blob = self.load_blob(backup_dir, MANIFEST_BLOB_NAME)?; + let blob = backup_dir.load_blob(MANIFEST_BLOB_NAME)?; let raw_size = blob.raw_size(); let manifest = BackupManifest::try_from(blob)?; Ok((manifest, raw_size)) diff --git a/src/backup/verify.rs b/src/backup/verify.rs index d8be501e..ee7f38b7 100644 --- a/src/backup/verify.rs +++ b/src/backup/verify.rs @@ -41,11 +41,10 @@ impl VerifyWorker { } fn verify_blob( - datastore: Arc, backup_dir: &BackupDir, info: &FileInfo, ) -> Result<(), Error> { - let blob = datastore.load_blob(backup_dir, &info.filename)?; + let blob = backup_dir.load_blob(&info.filename)?; let raw_size = blob.raw_size(); if raw_size != info.size { @@ -399,7 +398,7 @@ pub fn verify_backup_dir_with_lock( match archive_type(&info.filename)? { ArchiveType::FixedIndex => verify_fixed_index(verify_worker, backup_dir, info), ArchiveType::DynamicIndex => verify_dynamic_index(verify_worker, backup_dir, info), - ArchiveType::Blob => verify_blob(verify_worker.datastore.clone(), backup_dir, info), + ArchiveType::Blob => verify_blob(backup_dir, info), } });