[pbs-devel] [PATCH proxmox-backup 07/11] datastore: remove load_manifest_json

Stefan Reiter s.reiter at proxmox.com
Wed Oct 14 14:16:35 CEST 2020


There's no point in having that as a seperate method, just parse the
thing into a struct and write it back out correctly.

Also makes further changes to the method simpler.

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
 src/api2/admin/datastore.rs    |  8 ++++----
 src/api2/backup/environment.rs |  4 ++--
 src/backup/datastore.rs        | 15 ++-------------
 src/backup/verify.rs           |  2 +-
 4 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 3bfd807c..5824611b 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -1428,9 +1428,9 @@ fn get_notes(
     let allowed = (user_privs & PRIV_DATASTORE_READ) != 0;
     if !allowed { check_backup_owner(&datastore, backup_dir.group(), &userid)?; }
 
-    let manifest = datastore.load_manifest_json(&backup_dir)?;
+    let (manifest, _) = datastore.load_manifest(&backup_dir)?;
 
-    let notes = manifest["unprotected"]["notes"]
+    let notes = manifest.unprotected["notes"]
         .as_str()
         .unwrap_or("");
 
@@ -1481,9 +1481,9 @@ fn set_notes(
     let allowed = (user_privs & PRIV_DATASTORE_READ) != 0;
     if !allowed { check_backup_owner(&datastore, backup_dir.group(), &userid)?; }
 
-    let mut manifest = datastore.load_manifest_json(&backup_dir)?;
+    let (mut manifest, _) = datastore.load_manifest(&backup_dir)?;
 
-    manifest["unprotected"]["notes"] = notes.into();
+    manifest.unprotected["notes"] = notes.into();
 
     datastore.store_manifest(&backup_dir, manifest)?;
 
diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs
index b035f1e2..f00c2cd3 100644
--- a/src/api2/backup/environment.rs
+++ b/src/api2/backup/environment.rs
@@ -473,12 +473,12 @@ impl BackupEnvironment {
         }
 
         // check manifest
-        let mut manifest = self.datastore.load_manifest_json(&self.backup_dir)
+        let (mut manifest, _) = self.datastore.load_manifest(&self.backup_dir)
             .map_err(|err| format_err!("unable to load manifest blob - {}", err))?;
 
         let stats = serde_json::to_value(state.backup_stat)?;
 
-        manifest["unprotected"]["chunk_upload_stats"] = stats;
+        manifest.unprotected["chunk_upload_stats"] = stats;
 
         self.datastore.store_manifest(&self.backup_dir, manifest)
             .map_err(|err| format_err!("unable to store manifest blob - {}", err))?;
diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs
index d1758408..8ea9311a 100644
--- a/src/backup/datastore.rs
+++ b/src/backup/datastore.rs
@@ -6,7 +6,6 @@ use std::convert::TryFrom;
 
 use anyhow::{bail, format_err, Error};
 use lazy_static::lazy_static;
-use serde_json::Value;
 
 use proxmox::tools::fs::{replace_file, CreateOptions};
 
@@ -669,22 +668,12 @@ impl DataStore {
         Ok((manifest, raw_size))
     }
 
-    pub fn load_manifest_json(
-        &self,
-        backup_dir: &BackupDir,
-    ) -> Result<Value, Error> {
-        let blob = self.load_blob(backup_dir, MANIFEST_BLOB_NAME)?;
-        // no expected digest available
-        let manifest_data = blob.decode(None, None)?;
-        let manifest: Value = serde_json::from_slice(&manifest_data[..])?;
-        Ok(manifest)
-    }
-
     pub fn store_manifest(
         &self,
         backup_dir: &BackupDir,
-        manifest: Value,
+        manifest: BackupManifest,
     ) -> Result<(), Error> {
+        let manifest = serde_json::to_value(manifest)?;
         let manifest = serde_json::to_string_pretty(&manifest)?;
         let blob = DataBlob::encode(manifest.as_bytes(), None, true)?;
         let raw_data = blob.raw_data();
diff --git a/src/backup/verify.rs b/src/backup/verify.rs
index 5e1391d9..05b6ba86 100644
--- a/src/backup/verify.rs
+++ b/src/backup/verify.rs
@@ -368,7 +368,7 @@ pub fn verify_backup_dir(
         upid,
     };
     manifest.unprotected["verify_state"] = serde_json::to_value(verify_state)?;
-    datastore.store_manifest(&backup_dir, serde_json::to_value(manifest)?)
+    datastore.store_manifest(&backup_dir, manifest)
         .map_err(|err| format_err!("unable to store manifest blob - {}", err))?;
 
     Ok(error_count == 0)
-- 
2.20.1






More information about the pbs-devel mailing list