datastore: remove load_manifest_json

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@proxmox.com>
This commit is contained in:
Stefan Reiter 2020-10-14 14:16:35 +02:00 committed by Dietmar Maurer
parent bfa54f2e85
commit 883aa6d5a4
4 changed files with 9 additions and 20 deletions

View File

@ -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)?;

View File

@ -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))?;

View File

@ -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};
@ -623,22 +622,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();

View File

@ -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)