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 A0C3568ADB for ; Thu, 22 Jul 2021 15:41:09 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9D89B11DB0 for ; Thu, 22 Jul 2021 15:41:09 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 BC33B11D91 for ; Thu, 22 Jul 2021 15:41:07 +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 8AD6D42607 for ; Thu, 22 Jul 2021 15:41:07 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 22 Jul 2021 15:41:03 +0200 Message-Id: <20210722134106.1280517-5-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722134106.1280517-1-d.csapak@proxmox.com> References: <20210722134106.1280517-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.525 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup v2 4/7] tape: media_catalog: add local type aliases to make code more clear 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: Thu, 22 Jul 2021 13:41:09 -0000 by adding some type aliases like 'type Store = String', the more complex types/return values are easier to read. For example HashMap turns into: HashMap since those types are not public, the generated cargo docs, do not contain them Signed-off-by: Dominik Csapak --- src/tape/media_catalog.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/tape/media_catalog.rs b/src/tape/media_catalog.rs index f7fcdd0a..296d1d2f 100644 --- a/src/tape/media_catalog.rs +++ b/src/tape/media_catalog.rs @@ -31,9 +31,14 @@ use crate::{ }, }; +type Store = String; +type Snapshot = String; +type FileNr = u64; +type Chunk = [u8; 32]; + pub struct DatastoreContent { - pub snapshot_index: HashMap, // snapshot => file_nr - pub chunk_index: HashMap<[u8;32], u64>, // chunk => file_nr + pub snapshot_index: HashMap, + pub chunk_index: HashMap, } impl DatastoreContent { @@ -61,11 +66,11 @@ pub struct MediaCatalog { log_to_stdout: bool, - current_archive: Option<(Uuid, u64, String)>, // (uuid, file_nr, store) + current_archive: Option<(Uuid, FileNr, Store)>, - last_entry: Option<(Uuid, u64)>, + last_entry: Option<(Uuid, FileNr)>, - content: HashMap, + content: HashMap, pending: Vec, } @@ -363,13 +368,13 @@ impl MediaCatalog { } /// Accessor to content list - pub fn content(&self) -> &HashMap { + pub fn content(&self) -> &HashMap { &self.content } fn load_fast_catalog( file: &mut File, - ) -> Result, Error> { + ) -> Result, Error> { let mut list = Vec::new(); let file = BufReader::new(file); for line in file.lines() { @@ -391,7 +396,7 @@ impl MediaCatalog { pub fn snapshot_list( base_path: &Path, media_id: &MediaId, - ) -> Result, Error> { + ) -> Result, Error> { let uuid = &media_id.label.uuid; let mut path = base_path.to_owned(); @@ -531,7 +536,7 @@ impl MediaCatalog { } /// Returns the snapshot archive file number - pub fn lookup_snapshot(&self, store: &str, snapshot: &str) -> Option { + pub fn lookup_snapshot(&self, store: &str, snapshot: &str) -> Option { match self.content.get(store) { None => None, Some(content) => content.snapshot_index.get(snapshot).copied(), @@ -539,7 +544,7 @@ impl MediaCatalog { } /// Test if the catalog already contain a chunk - pub fn contains_chunk(&self, store: &str, digest: &[u8;32]) -> bool { + pub fn contains_chunk(&self, store: &str, digest: &Chunk) -> bool { match self.content.get(store) { None => false, Some(content) => content.chunk_index.contains_key(digest), @@ -547,7 +552,7 @@ impl MediaCatalog { } /// Returns the chunk archive file number - pub fn lookup_chunk(&self, store: &str, digest: &[u8;32]) -> Option { + pub fn lookup_chunk(&self, store: &str, digest: &Chunk) -> Option { match self.content.get(store) { None => None, Some(content) => content.chunk_index.get(digest).copied(), @@ -634,7 +639,7 @@ impl MediaCatalog { /// Only valid after start_chunk_archive. fn register_chunk( &mut self, - digest: &[u8;32], + digest: &Chunk, ) -> Result<(), Error> { let (file_number, store) = match self.current_archive { @@ -1052,7 +1057,7 @@ impl MediaSetCatalog { } /// Returns the media uuid and snapshot archive file number - pub fn lookup_snapshot(&self, store: &str, snapshot: &str) -> Option<(&Uuid, u64)> { + pub fn lookup_snapshot(&self, store: &str, snapshot: &str) -> Option<(&Uuid, FileNr)> { for (uuid, catalog) in self.catalog_list.iter() { if let Some(nr) = catalog.lookup_snapshot(store, snapshot) { return Some((uuid, nr)); @@ -1062,7 +1067,7 @@ impl MediaSetCatalog { } /// Test if the catalog already contain a chunk - pub fn contains_chunk(&self, store: &str, digest: &[u8;32]) -> bool { + pub fn contains_chunk(&self, store: &str, digest: &Chunk) -> bool { for catalog in self.catalog_list.values() { if catalog.contains_chunk(store, digest) { return true; @@ -1072,7 +1077,7 @@ impl MediaSetCatalog { } /// Returns the media uuid and chunk archive file number - pub fn lookup_chunk(&self, store: &str, digest: &[u8;32]) -> Option<(&Uuid, u64)> { + pub fn lookup_chunk(&self, store: &str, digest: &Chunk) -> Option<(&Uuid, FileNr)> { for (uuid, catalog) in self.catalog_list.iter() { if let Some(nr) = catalog.lookup_chunk(store, digest) { return Some((uuid, nr)); -- 2.30.2