From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A07DF602AA for ; Wed, 14 Oct 2020 14:16:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E69C79BCB for ; Wed, 14 Oct 2020 14:16:50 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id E134E9AC9 for ; Wed, 14 Oct 2020 14:16:47 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A99CD45D5F for ; Wed, 14 Oct 2020 14:16:47 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Wed, 14 Oct 2020 14:16:35 +0200 Message-Id: <20201014121639.25276-8-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201014121639.25276-1-s.reiter@proxmox.com> References: <20201014121639.25276-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.038 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [environment.rs, verify.rs, datastore.rs] Subject: [pbs-devel] [PATCH proxmox-backup 07/11] datastore: remove load_manifest_json X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Oct 2020 12:16:51 -0000 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 --- 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 { - 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