From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ronja.mits.lan by ronja.mits.lan with LMTP id CEO3FmQSfGbLIgAAxxbTJA (envelope-from ); Wed, 26 Jun 2024 15:06:44 +0200 Received: from proxmox-new.maurer-it.com (unknown [192.168.2.33]) by ronja.mits.lan (Postfix) with ESMTPS id 47AEEF63AFC; Wed, 26 Jun 2024 15:06:44 +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 2DB1148725; Wed, 26 Jun 2024 15:06:44 +0200 (CEST) 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 (4096 bits)) (No client certificate requested) by proxmox-new.maurer-it.com (Proxmox) with ESMTPS; Wed, 26 Jun 2024 15:06:42 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C0E8B1BFE; Wed, 26 Jun 2024 15:06:41 +0200 (CEST) From: Maximiliano Sandoval To: pbs-devel@lists.proxmox.com Date: Wed, 26 Jun 2024 15:05:58 +0200 Message-Id: <20240626130603.538973-1-m.sandoval@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [pbs-devel] [PATCH backup v2 1/6] replace get(key).is_some() with contains_key() 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: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" X-SPAM-LEVEL: Spam detection results: 0 DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods MAILING_LIST_MULTI -2 Multiple indicators imply a widely-seen list manager RAZOR2_CF_RANGE_51_100 2.43 Razor2 gives confidence level above 50% RAZOR2_CHECK 1.729 Listed in Razor2 (http://razor.sf.net/) 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_NONE 0.001 SPF: sender does not publish an SPF Record Fixes the clippy warning: warning: unnecessary use of `get(realm).is_some()` --> pbs-config/src/domains.rs:68:58 | 68 | realm == "pbs" || realm == "pam" || domains.sections.get(realm).is_some() | ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key(realm)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check Signed-off-by: Maximiliano Sandoval --- pbs-config/src/acl.rs | 2 +- pbs-config/src/domains.rs | 2 +- pbs-datastore/src/prune.rs | 2 +- src/api2/access/user.rs | 28 ++++++++++--------------- src/api2/config/changer.rs | 2 +- src/api2/config/datastore.rs | 2 +- src/api2/config/drive.rs | 2 +- src/api2/config/media_pool.rs | 11 +++++----- src/api2/config/metrics/influxdbhttp.rs | 2 +- src/api2/config/metrics/influxdbudp.rs | 2 +- src/api2/config/prune.rs | 2 +- src/api2/config/remote.rs | 11 +++++----- src/api2/config/sync.rs | 2 +- src/api2/config/tape_backup_job.rs | 2 +- src/api2/config/traffic_control.rs | 11 +++++----- src/api2/config/verify.rs | 2 +- src/api2/node/disks/directory.rs | 2 +- src/api2/node/disks/zfs.rs | 2 +- src/api2/tape/media.rs | 2 +- src/tape/encryption_keys.rs | 2 +- src/tape/media_catalog.rs | 2 +- 21 files changed, 43 insertions(+), 52 deletions(-) diff --git a/pbs-config/src/acl.rs b/pbs-config/src/acl.rs index f78d69cd..8a1423cc 100644 --- a/pbs-config/src/acl.rs +++ b/pbs-config/src/acl.rs @@ -1054,7 +1054,7 @@ acl:1:/storage/store1:user1@pbs:DatastoreBackup let node = tree.find_node(path); assert!(node.is_some()); if let Some(node) = node { - assert!(node.users.get(&user2).is_some()); + assert!(node.users.contains_key(&user2)); } } diff --git a/pbs-config/src/domains.rs b/pbs-config/src/domains.rs index 4a9beec3..5b6ce480 100644 --- a/pbs-config/src/domains.rs +++ b/pbs-config/src/domains.rs @@ -65,7 +65,7 @@ pub fn save_config(config: &SectionConfigData) -> Result<(), Error> { /// Check if a realm with the given name exists pub fn exists(domains: &SectionConfigData, realm: &str) -> bool { - realm == "pbs" || realm == "pam" || domains.sections.get(realm).is_some() + realm == "pbs" || realm == "pam" || domains.sections.contains_key(realm) } // shell completion helper diff --git a/pbs-datastore/src/prune.rs b/pbs-datastore/src/prune.rs index 96da5826..ad1493bf 100644 --- a/pbs-datastore/src/prune.rs +++ b/pbs-datastore/src/prune.rs @@ -55,7 +55,7 @@ fn mark_selections Result>( for info in list { let backup_id = info.backup_dir.relative_path(); - if mark.get(&backup_id).is_some() { + if mark.contains_key(&backup_id) { continue; } if info.protected { diff --git a/src/api2/access/user.rs b/src/api2/access/user.rs index e2b74237..97cf520a 100644 --- a/src/api2/access/user.rs +++ b/src/api2/access/user.rs @@ -147,11 +147,7 @@ pub fn create_user( let (mut section_config, _digest) = pbs_config::user::config()?; - if section_config - .sections - .get(config.userid.as_str()) - .is_some() - { + if section_config.sections.contains_key(config.userid.as_str()) { bail!("user '{}' already exists.", config.userid); } @@ -375,11 +371,10 @@ pub fn delete_user(userid: Userid, digest: Option) -> Result<(), Error> crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?; } - match config.sections.get(userid.as_str()) { - Some(_) => { - config.sections.remove(userid.as_str()); - } - None => bail!("user '{}' does not exist.", userid), + if config.sections.contains_key(userid.as_str()) { + config.sections.remove(userid.as_str()); + } else { + bail!("user '{}' does not exist.", userid); } pbs_config::user::save_config(&config)?; @@ -503,7 +498,7 @@ pub fn generate_token( let tokenid = Authid::from((userid.clone(), Some(token_name.clone()))); let tokenid_string = tokenid.to_string(); - if config.sections.get(&tokenid_string).is_some() { + if config.sections.contains_key(&tokenid_string) { bail!( "token '{}' for user '{}' already exists.", token_name.as_str(), @@ -654,15 +649,14 @@ pub fn delete_token( let tokenid = Authid::from((userid.clone(), Some(token_name.clone()))); let tokenid_string = tokenid.to_string(); - match config.sections.get(&tokenid_string) { - Some(_) => { - config.sections.remove(&tokenid_string); - } - None => bail!( + if config.sections.contains_key(&tokenid_string) { + config.sections.remove(&tokenid_string); + } else { + bail!( "token '{}' of user '{}' does not exist.", token_name.as_str(), userid - ), + ); } token_shadow::delete_secret(&tokenid)?; diff --git a/src/api2/config/changer.rs b/src/api2/config/changer.rs index 91286697..31a15aba 100644 --- a/src/api2/config/changer.rs +++ b/src/api2/config/changer.rs @@ -33,7 +33,7 @@ pub fn create_changer(config: ScsiTapeChanger) -> Result<(), Error> { let (mut section_config, _digest) = pbs_config::drive::config()?; - if section_config.sections.get(&config.name).is_some() { + if section_config.sections.contains_key(&config.name) { param_bail!("name", "Entry '{}' already exists", config.name); } diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 6b742acb..02887b86 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -118,7 +118,7 @@ pub fn create_datastore( let (section_config, _digest) = pbs_config::datastore::config()?; - if section_config.sections.get(&config.name).is_some() { + if section_config.sections.contains_key(&config.name) { param_bail!("name", "datastore '{}' already exists.", config.name); } diff --git a/src/api2/config/drive.rs b/src/api2/config/drive.rs index cf620aaf..1222ab20 100644 --- a/src/api2/config/drive.rs +++ b/src/api2/config/drive.rs @@ -34,7 +34,7 @@ pub fn create_drive(config: LtoTapeDrive) -> Result<(), Error> { let (mut section_config, _digest) = pbs_config::drive::config()?; - if section_config.sections.get(&config.name).is_some() { + if section_config.sections.contains_key(&config.name) { param_bail!("name", "Entry '{}' already exists", config.name); } diff --git a/src/api2/config/media_pool.rs b/src/api2/config/media_pool.rs index 4a4cec56..9b6080be 100644 --- a/src/api2/config/media_pool.rs +++ b/src/api2/config/media_pool.rs @@ -31,7 +31,7 @@ pub fn create_pool(config: MediaPoolConfig) -> Result<(), Error> { let (mut section_config, _digest) = pbs_config::media_pool::config()?; - if section_config.sections.get(&config.name).is_some() { + if section_config.sections.contains_key(&config.name) { param_bail!("name", "Media pool '{}' already exists", config.name); } @@ -225,11 +225,10 @@ pub fn delete_pool(name: String) -> Result<(), Error> { let (mut config, _digest) = pbs_config::media_pool::config()?; - match config.sections.get(&name) { - Some(_) => { - config.sections.remove(&name); - } - None => http_bail!(NOT_FOUND, "delete pool '{}' failed - no such pool", name), + if config.sections.contains_key(&name) { + config.sections.remove(&name); + } else { + http_bail!(NOT_FOUND, "delete pool '{}' failed - no such pool", name); } pbs_config::media_pool::save_config(&config)?; diff --git a/src/api2/config/metrics/influxdbhttp.rs b/src/api2/config/metrics/influxdbhttp.rs index 2b7811ff..bed29260 100644 --- a/src/api2/config/metrics/influxdbhttp.rs +++ b/src/api2/config/metrics/influxdbhttp.rs @@ -82,7 +82,7 @@ pub async fn create_influxdb_http_server(config: InfluxDbHttp) -> Result<(), Err let (mut metrics, _digest) = metrics::config()?; - if metrics.sections.get(&config.name).is_some() { + if metrics.sections.contains_key(&config.name) { bail!("metric server '{}' already exists.", config.name); } diff --git a/src/api2/config/metrics/influxdbudp.rs b/src/api2/config/metrics/influxdbudp.rs index c6efd5e2..c47a4e19 100644 --- a/src/api2/config/metrics/influxdbudp.rs +++ b/src/api2/config/metrics/influxdbudp.rs @@ -67,7 +67,7 @@ pub async fn create_influxdb_udp_server(config: InfluxDbUdp) -> Result<(), Error let (mut metrics, _digest) = metrics::config()?; - if metrics.sections.get(&config.name).is_some() { + if metrics.sections.contains_key(&config.name) { bail!("metric server '{}' already exists.", config.name); } diff --git a/src/api2/config/prune.rs b/src/api2/config/prune.rs index 4f7ce39c..7e946dd2 100644 --- a/src/api2/config/prune.rs +++ b/src/api2/config/prune.rs @@ -66,7 +66,7 @@ pub fn do_create_prune_job( let (mut section_config, _digest) = prune::config()?; - if section_config.sections.get(&config.id).is_some() { + if section_config.sections.contains_key(&config.id) { param_bail!("id", "job '{}' already exists.", config.id); } diff --git a/src/api2/config/remote.rs b/src/api2/config/remote.rs index 2511c5d5..8325dbce 100644 --- a/src/api2/config/remote.rs +++ b/src/api2/config/remote.rs @@ -89,7 +89,7 @@ pub fn create_remote(name: String, config: RemoteConfig, password: String) -> Re let (mut section_config, _digest) = pbs_config::remote::config()?; - if section_config.sections.get(&name).is_some() { + if section_config.sections.contains_key(&name) { param_bail!("name", "remote '{}' already exists.", name); } @@ -288,11 +288,10 @@ pub fn delete_remote(name: String, digest: Option) -> Result<(), Error> crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?; } - match config.sections.get(&name) { - Some(_) => { - config.sections.remove(&name); - } - None => http_bail!(NOT_FOUND, "remote '{}' does not exist.", name), + if config.sections.contains_key(&name) { + config.sections.remove(&name); + } else { + http_bail!(NOT_FOUND, "remote '{}' does not exist.", name); } pbs_config::remote::save_config(&config)?; diff --git a/src/api2/config/sync.rs b/src/api2/config/sync.rs index 8809465c..6fdc69a9 100644 --- a/src/api2/config/sync.rs +++ b/src/api2/config/sync.rs @@ -154,7 +154,7 @@ pub fn create_sync_job( let (mut section_config, _digest) = sync::config()?; - if section_config.sections.get(&config.id).is_some() { + if section_config.sections.contains_key(&config.id) { param_bail!("id", "job '{}' already exists.", config.id); } diff --git a/src/api2/config/tape_backup_job.rs b/src/api2/config/tape_backup_job.rs index e425cbb5..b6db9299 100644 --- a/src/api2/config/tape_backup_job.rs +++ b/src/api2/config/tape_backup_job.rs @@ -75,7 +75,7 @@ pub fn create_tape_backup_job( let (mut config, _digest) = pbs_config::tape_job::config()?; - if config.sections.get(&job.id).is_some() { + if config.sections.contains_key(&job.id) { param_bail!("id", "job '{}' already exists.", job.id); } diff --git a/src/api2/config/traffic_control.rs b/src/api2/config/traffic_control.rs index 30ea40ec..674a7404 100644 --- a/src/api2/config/traffic_control.rs +++ b/src/api2/config/traffic_control.rs @@ -59,7 +59,7 @@ pub fn create_traffic_control(config: TrafficControlRule) -> Result<(), Error> { let (mut section_config, _digest) = pbs_config::traffic_control::config()?; - if section_config.sections.get(&config.name).is_some() { + if section_config.sections.contains_key(&config.name) { param_bail!( "name", "traffic control rule '{}' already exists.", @@ -258,11 +258,10 @@ pub fn delete_traffic_control(name: String, digest: Option) -> Result<() crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?; } - match config.sections.get(&name) { - Some(_) => { - config.sections.remove(&name); - } - None => http_bail!(NOT_FOUND, "traffic control rule '{}' does not exist.", name), + if config.sections.contains_key(&name) { + config.sections.remove(&name); + } else { + http_bail!(NOT_FOUND, "traffic control rule '{}' does not exist.", name); } pbs_config::traffic_control::save_config(&config)?; diff --git a/src/api2/config/verify.rs b/src/api2/config/verify.rs index 82dbe43b..e71e0c2e 100644 --- a/src/api2/config/verify.rs +++ b/src/api2/config/verify.rs @@ -85,7 +85,7 @@ pub fn create_verification_job( let (mut section_config, _digest) = verify::config()?; - if section_config.sections.get(&config.id).is_some() { + if section_config.sections.contains_key(&config.id) { param_bail!("id", "job '{}' already exists.", config.id); } diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs index 9f1112a9..03c0053e 100644 --- a/src/api2/node/disks/directory.rs +++ b/src/api2/node/disks/directory.rs @@ -209,7 +209,7 @@ pub fn create_datastore_disk( let (config, _digest) = pbs_config::datastore::config()?; - if config.sections.get(&datastore.name).is_some() { + if config.sections.contains_key(&datastore.name) { bail!("datastore '{}' already exists.", datastore.name); } diff --git a/src/api2/node/disks/zfs.rs b/src/api2/node/disks/zfs.rs index 673dc1bf..7caeb4bb 100644 --- a/src/api2/node/disks/zfs.rs +++ b/src/api2/node/disks/zfs.rs @@ -315,7 +315,7 @@ pub fn create_zpool( let (config, _digest) = pbs_config::datastore::config()?; - if config.sections.get(&datastore.name).is_some() { + if config.sections.contains_key(&datastore.name) { bail!("datastore '{}' already exists.", datastore.name); } diff --git a/src/api2/tape/media.rs b/src/api2/tape/media.rs index 159906ba..a7c8483a 100644 --- a/src/api2/tape/media.rs +++ b/src/api2/tape/media.rs @@ -244,7 +244,7 @@ pub async fn list_media( let media_id = inventory.lookup_media(uuid).unwrap(); if let Some(pool) = media_id.pool() { - if config.sections.get(&pool).is_some() { + if config.sections.contains_key(&pool) { continue; } diff --git a/src/tape/encryption_keys.rs b/src/tape/encryption_keys.rs index 1f60c1c6..5f9f6d18 100644 --- a/src/tape/encryption_keys.rs +++ b/src/tape/encryption_keys.rs @@ -165,7 +165,7 @@ pub fn insert_key(key: [u8; 32], key_config: KeyConfig, force: bool) -> Result<( None => bail!("missing encryption key fingerprint - internal error"), }; - if !force && config_map.get(&fingerprint).is_some() { + if !force && config_map.contains_key(&fingerprint) { bail!("encryption key '{}' already exists.", fingerprint); } diff --git a/src/tape/media_catalog.rs b/src/tape/media_catalog.rs index 9aae0aa1..fa8ff405 100644 --- a/src/tape/media_catalog.rs +++ b/src/tape/media_catalog.rs @@ -946,7 +946,7 @@ impl MediaSetCatalog { /// Add a catalog pub fn append_catalog(&mut self, catalog: MediaCatalog) -> Result<(), Error> { - if self.catalog_list.get(&catalog.uuid).is_some() { + if self.catalog_list.contains_key(&catalog.uuid) { bail!("MediaSetCatalog already contains media '{}'", catalog.uuid); } -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel