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 7AD6391339 for ; Wed, 14 Feb 2024 09:24:08 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5C3E53F808 for ; Wed, 14 Feb 2024 09:23: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 ; Wed, 14 Feb 2024 09:23:36 +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 99D32480EE for ; Wed, 14 Feb 2024 09:23:36 +0100 (CET) From: Maximiliano Sandoval To: pbs-devel@lists.proxmox.com Date: Wed, 14 Feb 2024 09:23:35 +0100 Message-Id: <20240214082335.77143-2-m.sandoval@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240214082335.77143-1-m.sandoval@proxmox.com> References: <20240214082335.77143-1-m.sandoval@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.131 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 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_2 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_4 0.1 random spam to be learned in bayes 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_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [user.rs, proxmox-daily-update.rs] Subject: [pbs-devel] [PATCH backup v4 2/2] api: use if-let pattern for error-only handling 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: Wed, 14 Feb 2024 08:24:08 -0000 It is more readable than using match. We also inline variables in eprintln!. Signed-off-by: Maximiliano Sandoval --- pbs-client/src/pxar/dir_stack.rs | 9 +++------ src/api2/access/user.rs | 20 ++++---------------- src/bin/proxmox-daily-update.rs | 7 ++----- src/tape/pool_writer/new_chunks_iterator.rs | 9 +++------ src/tools/parallel_handler.rs | 11 ++++------- src/traffic_control_cache.rs | 7 ++----- 6 files changed, 18 insertions(+), 45 deletions(-) diff --git a/pbs-client/src/pxar/dir_stack.rs b/pbs-client/src/pxar/dir_stack.rs index 43cbee1d..616d7545 100644 --- a/pbs-client/src/pxar/dir_stack.rs +++ b/pbs-client/src/pxar/dir_stack.rs @@ -40,16 +40,13 @@ impl PxarDir { parent: RawFd, allow_existing_dirs: bool, ) -> Result { - match mkdirat( + if let Err(err) = mkdirat( parent, self.file_name.as_os_str(), perms_from_metadata(&self.metadata)?, ) { - Ok(()) => (), - Err(err) => { - if !(allow_existing_dirs && err.already_exists()) { - return Err(err.into()); - } + if !(allow_existing_dirs && err.already_exists()) { + return Err(err.into()); } } diff --git a/src/api2/access/user.rs b/src/api2/access/user.rs index 118838ce..a0be6111 100644 --- a/src/api2/access/user.rs +++ b/src/api2/access/user.rs @@ -381,28 +381,16 @@ pub fn delete_user(userid: Userid, digest: Option) -> Result<(), Error> pbs_config::user::save_config(&config)?; let authenticator = crate::auth::lookup_authenticator(userid.realm())?; - match authenticator.remove_password(userid.name()) { - Ok(()) => {} - Err(err) => { - eprintln!( - "error removing password after deleting user {:?}: {}", - userid, err - ); - } + if let Err(err) = authenticator.remove_password(userid.name()) { + eprintln!("error removing password after deleting user {userid:?}: {err}",); } - match crate::config::tfa::read().and_then(|mut cfg| { + if let Err(err) = crate::config::tfa::read().and_then(|mut cfg| { let _: proxmox_tfa::api::NeedsSaving = cfg.remove_user(&crate::config::tfa::UserAccess, userid.as_str())?; crate::config::tfa::write(&cfg) }) { - Ok(()) => (), - Err(err) => { - eprintln!( - "error updating TFA config after deleting user {:?}: {}", - userid, err - ); - } + eprintln!("error updating TFA config after deleting user {userid:?} {err}",); } Ok(()) diff --git a/src/bin/proxmox-daily-update.rs b/src/bin/proxmox-daily-update.rs index ae3744c5..c22609c5 100644 --- a/src/bin/proxmox-daily-update.rs +++ b/src/bin/proxmox-daily-update.rs @@ -55,11 +55,8 @@ async fn do_update(rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> { _ => unreachable!(), }; - match check_acme_certificates(rpcenv).await { - Ok(()) => (), - Err(err) => { - log::error!("error checking certificates: {}", err); - } + if let Err(err) = check_acme_certificates(rpcenv).await { + log::error!("error checking certificates: {err}"); } // TODO: cleanup tasks like in PVE? diff --git a/src/tape/pool_writer/new_chunks_iterator.rs b/src/tape/pool_writer/new_chunks_iterator.rs index ae75b7b1..1454b33d 100644 --- a/src/tape/pool_writer/new_chunks_iterator.rs +++ b/src/tape/pool_writer/new_chunks_iterator.rs @@ -57,12 +57,9 @@ impl NewChunksIterator { let blob = datastore.load_chunk(&digest)?; //println!("LOAD CHUNK {}", hex::encode(&digest)); - match tx.send(Ok(Some((digest, blob)))) { - Ok(()) => {} - Err(err) => { - eprintln!("could not send chunk to reader thread: {}", err); - break; - } + if let Err(err) = tx.send(Ok(Some((digest, blob)))) { + eprintln!("could not send chunk to reader thread: {err}"); + break; } chunk_index.insert(digest); diff --git a/src/tools/parallel_handler.rs b/src/tools/parallel_handler.rs index c4316ad0..17f70179 100644 --- a/src/tools/parallel_handler.rs +++ b/src/tools/parallel_handler.rs @@ -80,13 +80,10 @@ impl ParallelHandler { Ok(data) => data, Err(_) => return, }; - match (handler_fn)(data) { - Ok(()) => (), - Err(err) => { - let mut guard = abort.lock().unwrap(); - if guard.is_none() { - *guard = Some(err.to_string()); - } + if let Err(err) = (handler_fn)(data) { + let mut guard = abort.lock().unwrap(); + if guard.is_none() { + *guard = Some(err.to_string()); } } }) diff --git a/src/traffic_control_cache.rs b/src/traffic_control_cache.rs index 2e097d70..4c3bccee 100644 --- a/src/traffic_control_cache.rs +++ b/src/traffic_control_cache.rs @@ -164,11 +164,8 @@ impl TrafficControlCache { self.last_traffic_control_generation = traffic_control_generation; self.last_update = now; - match self.reload_impl() { - Ok(()) => (), - Err(err) => { - log::error!("TrafficControlCache::reload failed -> {}", err); - } + if let Err(err) = self.reload_impl() { + log::error!("TrafficControlCache::reload failed -> {err}"); } } -- 2.39.2