]> git.proxmox.com Git - proxmox-backup.git/commitdiff
datastore: move blob loading into BackupDir impl and adapt call sites
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 24 Apr 2022 17:09:38 +0000 (19:09 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 24 Apr 2022 18:16:58 +0000 (20:16 +0200)
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 <t.lamprecht@proxmox.com>
pbs-datastore/src/backup_info.rs
pbs-datastore/src/datastore.rs
src/backup/verify.rs

index e5bb7c522ce3ea96d3fca95e767b63d1a7d21fa1..2f1eaa6f8fc00a0688d142a9ff280310fb99e1fc 100644 (file)
@@ -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<DataBlob, Error> {
+        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
index 0ef7fe52bdd411571fac7c547cdbb2622abfc8a8..6df23c52952fefbecefa79d5d1661afe754b75e1 100644 (file)
@@ -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<DataBlob, Error> {
-        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<std::fs::Metadata, Error> {
         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))
index d8be501ed48e652bc1187737b0a6d7f0ac82aa48..ee7f38b77a380a33ca397a7d792d27252b071c67 100644 (file)
@@ -41,11 +41,10 @@ impl VerifyWorker {
 }
 
 fn verify_blob(
-    datastore: Arc<DataStore>,
     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),
             }
         });