]> git.proxmox.com Git - proxmox-backup.git/commitdiff
tape: factor getting encryption fingerprint tuple out
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 1 Feb 2024 15:23:42 +0000 (16:23 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 1 Feb 2024 15:25:22 +0000 (16:25 +0100)
makes it a bit more readable as there's less "noise" in the read_label
function and as the separate new fn allows us to nicely use ? to early
return as it has an option in the return signature avoiding 5 lines of
code while not really getting more terse.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/tape/drive/mod.rs
src/tape/inventory.rs

index 4f8f1295180518247cb67d7da363b9aaf1152101..8607d64b0ac1c1c5146397823091596ee4ce4da5 100644 (file)
@@ -198,16 +198,7 @@ pub trait TapeDriver {
     fn read_label(&mut self) -> Result<(Option<MediaId>, Option<KeyConfig>), Error> {
         let (media_id, key_config) = self.read_label_without_loading_key()?;
 
-        let encrypt_fingerprint = if let Some(media_set_label) =
-            media_id.as_ref().and_then(|id| id.media_set_label.clone())
-        {
-            media_set_label
-                .encryption_key_fingerprint
-                .clone()
-                .map(|fp| (fp, media_set_label.uuid.clone()))
-        } else {
-            None
-        };
+        let encrypt_fingerprint = media_id.as_ref().and_then(|id| id.get_encryption_fp());
 
         self.set_encryption(encrypt_fingerprint)?;
 
index 0b48c4a4e0831a0744f21d96083d51bb82808c26..7514d76c04e32293ddd9d46be0dd4dd9346ef61c 100644 (file)
@@ -33,7 +33,7 @@ use serde_json::json;
 use proxmox_sys::fs::{file_get_json, replace_file, CreateOptions};
 use proxmox_uuid::Uuid;
 
-use pbs_api_types::{MediaLocation, MediaSetPolicy, MediaStatus, RetentionPolicy};
+use pbs_api_types::{Fingerprint, MediaLocation, MediaSetPolicy, MediaStatus, RetentionPolicy};
 use pbs_config::BackupLockGuard;
 
 #[cfg(not(test))]
@@ -71,6 +71,10 @@ impl MediaId {
         }
         self.label.pool.to_owned()
     }
+    pub(crate) fn get_encryption_fp(&self) -> Option<(Fingerprint, Uuid)> {
+        let label = self.clone().media_set_label?;
+        label.encryption_key_fingerprint.map(|fp| (fp, label.uuid))
+    }
 }
 
 #[derive(Serialize, Deserialize)]