mirror of
git://git.proxmox.com/git/proxmox-backup.git
synced 2025-01-07 17:18:03 +03:00
don't call contains_key() before remove()
HashMap::remove() returns the value it removes as an Option<>, so instead of first checking if the key exists before removing it, just try to remove it and use the returned Option<> to test whether we should bail!(). Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
f4130d531f
commit
42c6224f92
@ -371,9 +371,7 @@ pub fn delete_user(userid: Userid, digest: Option<String>) -> Result<(), Error>
|
||||
crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?;
|
||||
}
|
||||
|
||||
if config.sections.contains_key(userid.as_str()) {
|
||||
config.sections.remove(userid.as_str());
|
||||
} else {
|
||||
if config.sections.remove(userid.as_str()).is_none() {
|
||||
bail!("user '{}' does not exist.", userid);
|
||||
}
|
||||
|
||||
@ -649,9 +647,7 @@ pub fn delete_token(
|
||||
let tokenid = Authid::from((userid.clone(), Some(token_name.clone())));
|
||||
let tokenid_string = tokenid.to_string();
|
||||
|
||||
if config.sections.contains_key(&tokenid_string) {
|
||||
config.sections.remove(&tokenid_string);
|
||||
} else {
|
||||
if config.sections.remove(&tokenid_string).is_none() {
|
||||
bail!(
|
||||
"token '{}' of user '{}' does not exist.",
|
||||
token_name.as_str(),
|
||||
|
@ -225,9 +225,7 @@ pub fn delete_pool(name: String) -> Result<(), Error> {
|
||||
|
||||
let (mut config, _digest) = pbs_config::media_pool::config()?;
|
||||
|
||||
if config.sections.contains_key(&name) {
|
||||
config.sections.remove(&name);
|
||||
} else {
|
||||
if config.sections.remove(&name).is_none() {
|
||||
http_bail!(NOT_FOUND, "delete pool '{}' failed - no such pool", name);
|
||||
}
|
||||
|
||||
|
@ -288,9 +288,7 @@ pub fn delete_remote(name: String, digest: Option<String>) -> Result<(), Error>
|
||||
crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?;
|
||||
}
|
||||
|
||||
if config.sections.contains_key(&name) {
|
||||
config.sections.remove(&name);
|
||||
} else {
|
||||
if config.sections.remove(&name).is_none() {
|
||||
http_bail!(NOT_FOUND, "remote '{}' does not exist.", name);
|
||||
}
|
||||
|
||||
|
@ -258,9 +258,7 @@ pub fn delete_traffic_control(name: String, digest: Option<String>) -> Result<()
|
||||
crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?;
|
||||
}
|
||||
|
||||
if config.sections.contains_key(&name) {
|
||||
config.sections.remove(&name);
|
||||
} else {
|
||||
if config.sections.remove(&name).is_none() {
|
||||
http_bail!(NOT_FOUND, "traffic control rule '{}' does not exist.", name);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user