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 73D8E909D5 for ; Mon, 12 Feb 2024 14:18:08 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4C6E61924C for ; Mon, 12 Feb 2024 14:17:38 +0100 (CET) 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 for ; Mon, 12 Feb 2024 14:17:37 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D5383478D2 for ; Mon, 12 Feb 2024 14:17:36 +0100 (CET) From: Maximiliano Sandoval To: pbs-devel@lists.proxmox.com Date: Mon, 12 Feb 2024 14:17:30 +0100 Message-Id: <20240212131734.454966-5-m.sandoval@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212131734.454966-1-m.sandoval@proxmox.com> References: <20240212131734.454966-1-m.sandoval@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -1.443 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy FSL_BULK_SIG 0.001 Bulk signature with no Unsubscribe KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RAZOR2_CF_RANGE_51_100 1.886 Razor2 gives confidence level above 50% RAZOR2_CHECK 0.922 Listed in Razor2 (http://razor.sf.net/) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_SBL_A 0.1 Contains URL's A record listed in the Spamhaus SBL blocklist [185.199.111.153, 185.199.109.153, 185.199.108.153, 185.199.110.153] Subject: [pbs-devel] [PATCH backup 05/13] use or_default instead of or_insert_with(Default::default) 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: Mon, 12 Feb 2024 13:18:08 -0000 We need to annotate some cases to allow the compile to infer the types. Fixes the clippy lint: ``` warning: use of `or_insert_with` to construct default value --> src/api2/tape/restore.rs:750:18 | 750 | .or_insert_with(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_or_default = note: `#[warn(clippy::unwrap_or_default)]` on by default ``` Signed-off-by: Maximiliano Sandoval --- pbs-config/src/acl.rs | 28 ++++++++-------------------- src/api2/tape/restore.rs | 14 +++++--------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/pbs-config/src/acl.rs b/pbs-config/src/acl.rs index cd9987fa..a0354a05 100644 --- a/pbs-config/src/acl.rs +++ b/pbs-config/src/acl.rs @@ -447,8 +447,8 @@ impl AclTree { } fn write_node_config(node: &AclTreeNode, path: &str, w: &mut dyn Write) -> Result<(), Error> { - let mut role_ug_map0 = HashMap::new(); - let mut role_ug_map1 = HashMap::new(); + let mut role_ug_map0: HashMap<_, BTreeSet<_>> = HashMap::new(); + let mut role_ug_map1: HashMap<_, BTreeSet<_>> = HashMap::new(); for (auth_id, roles) in &node.users { // no need to save, because root is always 'Administrator' @@ -459,15 +459,9 @@ impl AclTree { let role = role.as_str(); let auth_id = auth_id.to_string(); if *propagate { - role_ug_map1 - .entry(role) - .or_insert_with(BTreeSet::new) - .insert(auth_id); + role_ug_map1.entry(role).or_default().insert(auth_id); } else { - role_ug_map0 - .entry(role) - .or_insert_with(BTreeSet::new) - .insert(auth_id); + role_ug_map0.entry(role).or_default().insert(auth_id); } } } @@ -476,15 +470,9 @@ impl AclTree { for (role, propagate) in roles { let group = format!("@{}", group); if *propagate { - role_ug_map1 - .entry(role) - .or_insert_with(BTreeSet::new) - .insert(group); + role_ug_map1.entry(role).or_default().insert(group); } else { - role_ug_map0 - .entry(role) - .or_insert_with(BTreeSet::new) - .insert(group); + role_ug_map0.entry(role).or_default().insert(group); } } } @@ -492,7 +480,7 @@ impl AclTree { fn group_by_property_list( item_property_map: &HashMap<&str, BTreeSet>, ) -> BTreeMap> { - let mut result_map = BTreeMap::new(); + let mut result_map: BTreeMap<_, BTreeSet<_>> = BTreeMap::new(); for (item, property_map) in item_property_map { let item_list = property_map.iter().fold(String::new(), |mut acc, v| { if !acc.is_empty() { @@ -503,7 +491,7 @@ impl AclTree { }); result_map .entry(item_list) - .or_insert_with(BTreeSet::new) + .or_default() .insert(item.to_string()); } result_map diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs index 47e0586b..8273c867 100644 --- a/src/api2/tape/restore.rs +++ b/src/api2/tape/restore.rs @@ -75,7 +75,7 @@ impl TryFrom> for NamespaceMap { let max_depth = mapping.max_depth.unwrap_or(MAX_NAMESPACE_DEPTH); let ns_map: &mut HashMap = - map.entry(mapping.store).or_insert_with(HashMap::new); + map.entry(mapping.store).or_default(); if ns_map.insert(source, (target, max_depth)).is_some() { bail!("duplicate mapping found"); @@ -747,7 +747,7 @@ fn restore_list_worker( let file_list = snapshot_file_hash .entry(media_id.label.uuid.clone()) - .or_insert_with(Vec::new); + .or_default(); file_list.push(file_num); task_log!( @@ -808,10 +808,8 @@ fn restore_list_worker( // we only want to restore chunks that we do not have yet if !datastore.cond_touch_chunk(&digest, false)? { if let Some((uuid, nr)) = catalog.lookup_chunk(&source_datastore, &digest) { - let file = media_file_chunk_map - .entry(uuid.clone()) - .or_insert_with(BTreeMap::new); - let chunks = file.entry(nr).or_insert_with(HashSet::new); + let file = media_file_chunk_map.entry(uuid.clone()).or_default(); + let chunks = file.entry(nr).or_default(); chunks.insert(digest); } } @@ -1089,9 +1087,7 @@ fn restore_snapshots_to_tmpdir( ); std::fs::create_dir_all(&tmp_path)?; - let chunks = chunks_list - .entry(source_datastore) - .or_insert_with(HashSet::new); + let chunks = chunks_list.entry(source_datastore).or_default(); let manifest = try_restore_snapshot_archive(worker.clone(), &mut decoder, &tmp_path)?; -- 2.39.2