[pbs-devel] [PATCH backup v2 1/6] replace get(key).is_some() with contains_key()
Maximiliano Sandoval
m.sandoval at proxmox.com
Wed Jun 26 15:05:58 CEST 2024
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 <m.sandoval at proxmox.com>
---
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 at 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<F: Fn(&BackupInfo) -> Result<String, Error>>(
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<String>) -> 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<String>) -> 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<String>) -> 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
More information about the pbs-devel
mailing list