]> git.proxmox.com Git - pve-installer.git/commitdiff
simplify some code
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 23 Apr 2024 07:51:23 +0000 (09:51 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 23 Apr 2024 08:02:39 +0000 (10:02 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-auto-installer/src/sysinfo.rs
proxmox-auto-installer/src/utils.rs
proxmox-fetch-answer/src/fetch_plugins/http.rs
proxmox-installer-common/src/disk_checks.rs
proxmox-installer-common/src/setup.rs

index a9b9ffdfba05de931c37e750c93accbc1200f114..05f7f5050a5bb9b2bf92dd5f0db699d0b53f1565 100644 (file)
@@ -76,22 +76,23 @@ struct SystemDMI {
 
 impl SystemDMI {
     pub(crate) fn get() -> Result<Self> {
-        let system_files = vec![
+        let system_files = [
             "product_serial",
             "product_sku",
             "product_uuid",
             "product_name",
         ];
-        let baseboard_files = vec!["board_asset_tag", "board_serial", "board_name"];
-        let chassis_files = vec!["chassis_serial", "chassis_sku", "chassis_asset_tag"];
+        let baseboard_files = ["board_asset_tag", "board_serial", "board_name"];
+        let chassis_files = ["chassis_serial", "chassis_sku", "chassis_asset_tag"];
 
         Ok(Self {
-            system: Self::get_dmi_infos(system_files)?,
-            baseboard: Self::get_dmi_infos(baseboard_files)?,
-            chassis: Self::get_dmi_infos(chassis_files)?,
+            system: Self::get_dmi_infos(&system_files)?,
+            baseboard: Self::get_dmi_infos(&baseboard_files)?,
+            chassis: Self::get_dmi_infos(&chassis_files)?,
         })
     }
-    fn get_dmi_infos(files: Vec<&str>) -> Result<HashMap<String, String>> {
+
+    fn get_dmi_infos(files: &[&str]) -> Result<HashMap<String, String>> {
         let mut res: HashMap<String, String> = HashMap::new();
 
         for file in files {
index f393590262bb39e0493f4dfa003f9dd4b7562306..55887887a434cc617ee2a9186216f6586fc5b748 100644 (file)
@@ -101,8 +101,7 @@ pub fn get_nic_list() -> Result<Vec<String>> {
         .arg("-j")
         .arg("link")
         .output()?;
-    let parsed_links: Vec<IpLinksUdevInfo> =
-        serde_json::from_str(String::from_utf8(ip_output.stdout)?.as_str())?;
+    let parsed_links: Vec<IpLinksUdevInfo> = serde_json::from_slice(&ip_output.stdout)?;
     let mut links: Vec<String> = Vec::new();
 
     for link in parsed_links {
index ae29196e068bdf3b33568d410d26ca4b4bf6a30c..11641e82f8d86c9106d1d152a08cc223a9838fd4 100644 (file)
@@ -60,9 +60,8 @@ impl FetchFromHTTP {
             };
         }
 
-        if fingerprint.is_some() {
-            let fp = fingerprint.clone();
-            fs::write("/tmp/cert_fingerprint", fp.unwrap()).ok();
+        if let Some(fingerprint) = &fingerprint {
+            let _ = fs::write("/tmp/cert_fingerprint", fingerprint);
         }
 
         info!("Gathering system information.");
index 7cbdf1933846125e26c838def3665a234f1d6846..89b300cb055d1bbd94df40ca9fd3505334da17e9 100644 (file)
@@ -42,9 +42,7 @@ pub fn check_raid_min_disks(disks: &[Disk], min: usize) -> Result<(), String> {
 /// * `runinfo` - `RuntimeInfo` instance of currently running system
 /// * `disks` - List of disks designated as bootdisk targets.
 pub fn check_disks_4kn_legacy_boot(boot_type: BootType, disks: &[Disk]) -> Result<(), &str> {
-    let is_blocksize_4096 = |disk: &Disk| disk.block_size.map(|s| s == 4096).unwrap_or(false);
-
-    if boot_type == BootType::Bios && disks.iter().any(is_blocksize_4096) {
+    if boot_type == BootType::Bios && disks.iter().any(|disk| disk.block_size == Some(4096)) {
         return Err("Booting from 4Kn drive in legacy BIOS mode is not supported.");
     }
 
index c4a92f9f1fff63e9ccb043dd7adca23303c97755..8a7bdee33a33346242ccaf2f666c8c47f73bd22a 100644 (file)
@@ -40,11 +40,11 @@ impl ProxmoxProduct {
 
 impl fmt::Display for ProxmoxProduct {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        match self {
-            Self::PVE => write!(f, "pve"),
-            Self::PMG => write!(f, "pmg"),
-            Self::PBS => write!(f, "pbs"),
-        }
+        f.write_str(match self {
+            Self::PVE => "pve",
+            Self::PMG => "pmg",
+            Self::PBS => "pbs",
+        })
     }
 }