[pbs-devel] [PATCH proxmox-backup 01/12] api2/tape: clippy fixes

Dominik Csapak d.csapak at proxmox.com
Tue Apr 6 08:27:36 CEST 2021


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 <d.csapak at proxmox.com>
---
 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<String>,
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<String> 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






More information about the pbs-devel mailing list