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 A94A070CCC for ; Tue, 6 Apr 2021 08:28:19 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5962D29BAB for ; Tue, 6 Apr 2021 08:27:53 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 id B23CE29B69 for ; Tue, 6 Apr 2021 08:27:51 +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 7ECCC40629 for ; Tue, 6 Apr 2021 08:27:51 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 6 Apr 2021 08:27:36 +0200 Message-Id: <20210406062747.9356-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210406062747.9356-1-d.csapak@proxmox.com> References: <20210406062747.9356-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.171 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 01/12] api2/tape: clippy fixes 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: Tue, 06 Apr 2021 06:28:19 -0000 fixes: * too_many_arguments * `if let Err(_) = ` => `.is_err()` * combine if branches * remove unnecessary lifetime * remove unnecessary return * `.len() == 0` => `.is_empty()` * `find().is_some()` => `.any()` Signed-off-by: Dominik Csapak --- src/api2/config/tape_backup_job.rs | 1 + src/api2/tape/backup.rs | 2 +- src/api2/tape/media.rs | 42 ++++++++++++++---------------- src/api2/tape/restore.rs | 12 ++++----- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/api2/config/tape_backup_job.rs b/src/api2/config/tape_backup_job.rs index caea4e18..70d1f6af 100644 --- a/src/api2/config/tape_backup_job.rs +++ b/src/api2/config/tape_backup_job.rs @@ -219,6 +219,7 @@ pub enum DeletableProperty { }, )] /// Update the tape backup job +#[allow(clippy::too_many_arguments)] pub fn update_tape_backup_job( id: String, store: Option, diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs index ec35038a..25d746fb 100644 --- a/src/api2/tape/backup.rs +++ b/src/api2/tape/backup.rs @@ -601,7 +601,7 @@ pub fn backup_snapshot( } } - if let Err(_) = reader_thread.join() { + if reader_thread.join().is_err() { bail!("chunk reader thread failed"); } diff --git a/src/api2/tape/media.rs b/src/api2/tape/media.rs index 811fcb7e..b1497fb3 100644 --- a/src/api2/tape/media.rs +++ b/src/api2/tape/media.rs @@ -173,32 +173,30 @@ pub async fn list_media( let inventory = Inventory::load(status_path)?; let privs = user_info.lookup_privs(&auth_id, &["tape", "pool"]); - if (privs & PRIV_TAPE_AUDIT) != 0 { - if pool.is_none() { + if (privs & PRIV_TAPE_AUDIT) != 0 && pool.is_none() { - for media_id in inventory.list_unassigned_media() { + for media_id in inventory.list_unassigned_media() { - let (mut status, location) = inventory.status_and_location(&media_id.label.uuid); + let (mut status, location) = inventory.status_and_location(&media_id.label.uuid); - if status == MediaStatus::Unknown { - status = MediaStatus::Writable; - } - - list.push(MediaListEntry { - uuid: media_id.label.uuid.clone(), - ctime: media_id.label.ctime, - label_text: media_id.label.label_text.to_string(), - location, - status, - catalog: true, // empty, so we do not need a catalog - expired: false, - media_set_uuid: None, - media_set_name: None, - media_set_ctime: None, - seq_nr: None, - pool: None, - }); + if status == MediaStatus::Unknown { + status = MediaStatus::Writable; } + + list.push(MediaListEntry { + uuid: media_id.label.uuid.clone(), + ctime: media_id.label.ctime, + label_text: media_id.label.label_text.to_string(), + location, + status, + catalog: true, // empty, so we do not need a catalog + expired: false, + media_set_uuid: None, + media_set_name: None, + media_set_ctime: None, + seq_nr: None, + pool: None, + }); } } diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs index 78aac73c..d8b81496 100644 --- a/src/api2/tape/restore.rs +++ b/src/api2/tape/restore.rs @@ -136,7 +136,7 @@ impl TryFrom for DataStoreMap { } impl DataStoreMap { - fn used_datastores<'a>(&self) -> HashSet<&str> { + fn used_datastores(&self) -> HashSet<&str> { let mut set = HashSet::new(); for store in self.map.values() { set.insert(store.name()); @@ -157,7 +157,7 @@ impl DataStoreMap { return Some(&store); } - return None; + None } } @@ -211,7 +211,7 @@ pub fn restore( let store_map = DataStoreMap::try_from(store) .map_err(|err| format_err!("cannot parse store mapping: {}", err))?; let used_datastores = store_map.used_datastores(); - if used_datastores.len() == 0 { + if used_datastores.is_empty() { bail!("no datastores given"); } @@ -351,6 +351,7 @@ pub fn restore( } /// Request and restore complete media without using existing catalog (create catalog instead) +#[allow(clippy::too_many_arguments)] pub fn request_and_restore_media( worker: &WorkerTask, media_id: &MediaId, @@ -843,13 +844,12 @@ pub fn fast_catalog_restore( let wanted = media_set .media_list() .iter() - .find(|e| { + .any(|e| { match e { None => false, Some(uuid) => uuid == catalog_uuid, } - }) - .is_some(); + }); if !wanted { task_log!(worker, "skip catalog because media '{}' not inventarized", catalog_uuid); -- 2.20.1