]> git.proxmox.com Git - proxmox-backup.git/commitdiff
clippy: us *_or_else with function calls
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 19 Jan 2021 13:04:46 +0000 (14:04 +0100)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 20 Jan 2021 15:23:54 +0000 (16:23 +0100)
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
18 files changed:
src/api2/admin/datastore.rs
src/api2/pull.rs
src/api2/types/userid.rs
src/backup/async_index_reader.rs
src/config/datastore.rs
src/config/drive.rs
src/config/media_pool.rs
src/config/network.rs
src/config/remote.rs
src/config/sync.rs
src/config/user.rs
src/server/email_notifications.rs
src/server/rest.rs
src/server/worker_task.rs
src/tape/drive/linux_list_drives.rs
src/tape/inventory.rs
src/tape/media_pool.rs
src/tools/logrotate.rs

index 09cde15e955cb62167b24a2a12b6583aa27d6452..c3d4d5f1e5db50ef766d59593b5d8bb5e6980aae 100644 (file)
@@ -1493,7 +1493,7 @@ fn pxar_file_download(
 
         let mut split = components.splitn(2, |c| *c == b'/');
         let pxar_name = std::str::from_utf8(split.next().unwrap())?;
-        let file_path = split.next().ok_or(format_err!("filepath looks strange '{}'", filepath))?;
+        let file_path = split.next().ok_or_else(|| format_err!("filepath looks strange '{}'", filepath))?;
         let (manifest, files) = read_backup_index(&datastore, &backup_dir)?;
         for file in files {
             if file.filename == pxar_name && file.crypt_mode == Some(CryptMode::Encrypt) {
@@ -1520,7 +1520,7 @@ fn pxar_file_download(
         let root = decoder.open_root().await?;
         let file = root
             .lookup(OsStr::from_bytes(file_path)).await?
-            .ok_or(format_err!("error opening '{:?}'", file_path))?;
+            .ok_or_else(|| format_err!("error opening '{:?}'", file_path))?;
 
         let body = match file.kind() {
             EntryKind::File { .. } => Body::wrap_stream(
index 77f9746e8265edc2de1691d8fff826d2453ca626..101ab3084576d95a03d25de59ebf825e6f6c5941 100644 (file)
@@ -88,7 +88,7 @@ pub fn do_sync_job(
             let worker_future = async move {
 
                 let delete = sync_job.remove_vanished.unwrap_or(true);
-                let sync_owner = sync_job.owner.unwrap_or(Authid::root_auth_id().clone());
+                let sync_owner = sync_job.owner.unwrap_or_else(|| Authid::root_auth_id().clone());
                 let (client, src_repo, tgt_store) = get_pull_parameters(&sync_job.store, &sync_job.remote, &sync_job.remote_store).await?;
 
                 worker.log(format!("Starting datastore sync job '{}'", job_id));
index 0ad64954d10b189a00a9b060f5993a0759193409..85c1edd1eb61819c91e7e806cd07d1019435c0a1 100644 (file)
@@ -638,7 +638,7 @@ impl std::str::FromStr for Authid {
             .iter()
             .rposition(|&b| b == b'!')
             .map(|pos| if pos < name_len { id.len() } else { pos })
-            .unwrap_or(id.len());
+            .unwrap_or_else(|| id.len());
 
         if realm_end == id.len() - 1 {
             bail!("empty token name in userid");
@@ -670,7 +670,7 @@ impl TryFrom<String> for Authid {
             .iter()
             .rposition(|&b| b == b'!')
             .map(|pos| if pos < name_len { data.len() } else { pos })
-            .unwrap_or(data.len());
+            .unwrap_or_else(|| data.len());
 
         if realm_end == data.len() - 1 {
             bail!("empty token name in userid");
index 2a04282c703d5f4b065a564f51ae7d659f57e579..60c68d4fc23e56f97f194662962d6b828cd0f8f4 100644 (file)
@@ -97,7 +97,7 @@ where
                     let info = this
                         .index
                         .chunk_info(idx)
-                        .ok_or(io_format_err!("could not get digest"))?;
+                        .ok_or_else(|| io_format_err!("could not get digest"))?;
 
                     this.current_chunk_offset = offset;
                     this.current_chunk_idx = idx;
index 4c3031fca8f3955f6349d67f90e82ddbec1c2ee7..e8f552fdfdb47ab81a86cd911dd4b4bc8a30cd36 100644 (file)
@@ -135,8 +135,8 @@ pub const DATASTORE_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.datastore.lck";
 
 pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
 
-    let content = proxmox::tools::fs::file_read_optional_string(DATASTORE_CFG_FILENAME)?;
-    let content = content.unwrap_or(String::from(""));
+    let content = proxmox::tools::fs::file_read_optional_string(DATASTORE_CFG_FILENAME)?
+        .unwrap_or_else(|| "".to_string());
 
     let digest = openssl::sha::sha256(content.as_bytes());
     let data = CONFIG.parse(DATASTORE_CFG_FILENAME, &content)?;
index 72bc05af538e607f6330dc9591bac1ef23483ef3..32ec3c4f9b105cd506d26d23834c709094723eff 100644 (file)
@@ -68,8 +68,8 @@ pub fn lock() -> Result<std::fs::File, Error> {
 
 pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
 
-    let content = proxmox::tools::fs::file_read_optional_string(DRIVE_CFG_FILENAME)?;
-    let content = content.unwrap_or(String::from(""));
+    let content = proxmox::tools::fs::file_read_optional_string(DRIVE_CFG_FILENAME)?
+        .unwrap_or_else(|| "".to_string());
 
     let digest = openssl::sha::sha256(content.as_bytes());
     let data = CONFIG.parse(DRIVE_CFG_FILENAME, &content)?;
index 5e1184e34d85d6e6a2e4970bfb4d74df6da98ddd..768cc6d9a29004961ca352f9c729625ee1742e29 100644 (file)
@@ -52,8 +52,8 @@ pub fn lock() -> Result<std::fs::File, Error> {
 
 pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
 
-    let content = proxmox::tools::fs::file_read_optional_string(MEDIA_POOL_CFG_FILENAME)?;
-    let content = content.unwrap_or(String::from(""));
+    let content = proxmox::tools::fs::file_read_optional_string(MEDIA_POOL_CFG_FILENAME)?
+        .unwrap_or_else(|| "".to_string());
 
     let digest = openssl::sha::sha256(content.as_bytes());
     let data = CONFIG.parse(MEDIA_POOL_CFG_FILENAME, &content)?;
index fbfef052bc66846ae0d253537b6c450affb5d5cf..4241261a08806b8f5fc722c1fe1bd22a98334667 100644 (file)
@@ -386,9 +386,9 @@ impl NetworkConfig {
     pub fn check_mtu(&self, parent_name: &str, child_name: &str) -> Result<(), Error> {
 
         let parent = self.interfaces.get(parent_name)
-            .ok_or(format_err!("check_mtu - missing parent interface '{}'", parent_name))?;
+            .ok_or_else(|| format_err!("check_mtu - missing parent interface '{}'", parent_name))?;
         let child = self.interfaces.get(child_name)
-            .ok_or(format_err!("check_mtu - missing child interface '{}'", child_name))?;
+            .ok_or_else(|| format_err!("check_mtu - missing child interface '{}'", child_name))?;
 
         let child_mtu = match child.mtu {
             Some(mtu) => mtu,
index 20fd39d4437926ed5f7caa7f47804ed3d9d7e248..9315575ba1e675390e87ec4465025d9c6c11e460 100644 (file)
@@ -92,8 +92,8 @@ pub const REMOTE_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.remote.lck";
 
 pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
 
-    let content = proxmox::tools::fs::file_read_optional_string(REMOTE_CFG_FILENAME)?;
-    let content = content.unwrap_or(String::from(""));
+    let content = proxmox::tools::fs::file_read_optional_string(REMOTE_CFG_FILENAME)?
+        .unwrap_or_else(|| "".to_string());
 
     let digest = openssl::sha::sha256(content.as_bytes());
     let data = CONFIG.parse(REMOTE_CFG_FILENAME, &content)?;
index 0d9be9dcaf0892bf3148e7931672c55f66e93ffc..8febc5d84460a27c89fa9e3cd223d144d81bfb53 100644 (file)
@@ -183,8 +183,8 @@ pub const SYNC_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.sync.lck";
 
 pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
 
-    let content = proxmox::tools::fs::file_read_optional_string(SYNC_CFG_FILENAME)?;
-    let content = content.unwrap_or(String::from(""));
+    let content = proxmox::tools::fs::file_read_optional_string(SYNC_CFG_FILENAME)?
+        .unwrap_or_else(|| "".to_string());
 
     let digest = openssl::sha::sha256(content.as_bytes());
     let data = CONFIG.parse(SYNC_CFG_FILENAME, &content)?;
index 3254183b384255ba233bc72a43e79e8305acebdc..cd9559276978bf6a842a76e857b17efd3ff4308c 100644 (file)
@@ -157,8 +157,8 @@ pub const USER_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.user.lck";
 
 pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
 
-    let content = proxmox::tools::fs::file_read_optional_string(USER_CFG_FILENAME)?;
-    let content = content.unwrap_or(String::from(""));
+    let content = proxmox::tools::fs::file_read_optional_string(USER_CFG_FILENAME)?
+        .unwrap_or_else(|| "".to_string());
 
     let digest = openssl::sha::sha256(content.as_bytes());
     let mut data = CONFIG.parse(USER_CFG_FILENAME, &content)?;
index f35d1b9475d7f93b0ea4b519db4a8d4cf36075c4..24c15073a572144e0676efc204eda71060180205 100644 (file)
@@ -456,7 +456,7 @@ fn handlebars_humam_bytes_helper(
 ) -> HelperResult {
     let param = h.param(0).map(|v| v.value().as_u64())
         .flatten()
-        .ok_or(RenderError::new("human-bytes: param not found"))?;
+        .ok_or_else(|| RenderError::new("human-bytes: param not found"))?;
 
     out.write(&HumanByte::from(param).to_string())?;
 
@@ -472,10 +472,10 @@ fn handlebars_relative_percentage_helper(
 ) -> HelperResult {
     let param0 = h.param(0).map(|v| v.value().as_f64())
         .flatten()
-        .ok_or(RenderError::new("relative-percentage: param0 not found"))?;
+        .ok_or_else(|| RenderError::new("relative-percentage: param0 not found"))?;
     let param1 = h.param(1).map(|v| v.value().as_f64())
         .flatten()
-        .ok_or(RenderError::new("relative-percentage: param1 not found"))?;
+        .ok_or_else(|| RenderError::new("relative-percentage: param1 not found"))?;
 
     if param1 == 0.0 {
         out.write("-")?;
index 67fbbbb29c426365edb963b7042b3f02a6e73084..0586979a6ef1343735ffb7313b7e9a1638b56af8 100644 (file)
@@ -147,7 +147,7 @@ fn log_response(
         let now = proxmox::tools::time::epoch_i64();
         // time format which apache/nginx use (by default), copied from pve-http-server
         let datetime = proxmox::tools::time::strftime_local("%d/%m/%Y:%H:%M:%S %z", now)
-            .unwrap_or("-".into());
+            .unwrap_or_else(|_| "-".to_string());
 
         logfile
             .lock()
@@ -161,7 +161,7 @@ fn log_response(
                 path,
                 status.as_str(),
                 resp.body().size_hint().lower(),
-                user_agent.unwrap_or("-".into()),
+                user_agent.unwrap_or_else(|| "-".to_string()),
             ));
     }
 }
index 0d884ba194f717e723c7665854e0ef89e81a64bb..967814c9d8512fcc27a02e848db1617c5af7900f 100644 (file)
@@ -330,7 +330,7 @@ pub fn rotate_task_log_archive(size_threshold: u64, compress: bool, max_files: O
     let _lock = lock_task_list_files(true)?;
 
     let mut logrotate = LogRotate::new(PROXMOX_BACKUP_ARCHIVE_TASK_FN, compress)
-        .ok_or(format_err!("could not get archive file names"))?;
+        .ok_or_else(|| format_err!("could not get archive file names"))?;
 
     logrotate.rotate(size_threshold, None, max_files)
 }
index 1b5926d1cca90b451eb8c252690d16fee4e2aaea..e3ab952449b87fb4da37a4a38d91babc42658434 100644 (file)
@@ -85,12 +85,12 @@ pub fn linux_tape_changer_list() -> Vec<TapeDeviceInfo> {
         let vendor = device.property_value("ID_VENDOR")
             .map(std::ffi::OsString::from)
             .and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
-            .unwrap_or(String::from("unknown"));
+            .unwrap_or_else(|| String::from("unknown"));
 
         let model = device.property_value("ID_MODEL")
             .map(std::ffi::OsString::from)
             .and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
-            .unwrap_or(String::from("unknown"));
+            .unwrap_or_else(|| String::from("unknown"));
 
         let dev_path = format!("/dev/tape/by-id/scsi-{}", serial);
 
@@ -166,12 +166,12 @@ pub fn linux_tape_device_list() -> Vec<TapeDeviceInfo> {
         let vendor = device.property_value("ID_VENDOR")
             .map(std::ffi::OsString::from)
             .and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
-            .unwrap_or(String::from("unknown"));
+            .unwrap_or_else(|| String::from("unknown"));
 
         let model = device.property_value("ID_MODEL")
             .map(std::ffi::OsString::from)
             .and_then(|s| if let Ok(s) = s.into_string() { Some(s) } else { None })
-            .unwrap_or(String::from("unknown"));
+            .unwrap_or_else(|| String::from("unknown"));
 
         let dev_path = format!("/dev/tape/by-id/scsi-{}-nst", serial);
 
index 289ef510a2133134ced5a196f65b0d281e995971..446d937932a9cd2335486f6c2a19b98cc4e69586 100644 (file)
@@ -522,7 +522,7 @@ impl Inventory {
     ) -> Result<String, Error> {
 
         if let Some(ctime) = self.media_set_start_time(media_set_uuid) {
-            let mut template = template.unwrap_or(String::from("%c"));
+            let mut template = template.unwrap_or_else(|| String::from("%c"));
             template = template.replace("%id%", &media_set_uuid.to_string());
             proxmox::tools::time::strftime_local(&template, ctime)
         } else {
index 08e2a16baa6df797a8b7968dc7a29dc964fe85c0..0499d3ed074e3d6d24d23fd1e783a71662c89106 100644 (file)
@@ -89,9 +89,9 @@ impl MediaPool {
         use_offline_media: bool,
     ) -> Result<Self, Error> {
 
-        let allocation = config.allocation.clone().unwrap_or(String::from("continue")).parse()?;
+        let allocation = config.allocation.clone().unwrap_or_else(|| String::from("continue")).parse()?;
 
-        let retention = config.retention.clone().unwrap_or(String::from("keep")).parse()?;
+        let retention = config.retention.clone().unwrap_or_else(|| String::from("keep")).parse()?;
 
         let encrypt_fingerprint = match config.encrypt {
             Some(ref fingerprint) => Some(fingerprint.parse()?),
index 354e9c6a317ac4b113ea21de122f2e08e7ea7f2d..5d026e8ccf77dd1df11d24fda0dc74f3937a2378 100644 (file)
@@ -104,8 +104,8 @@ impl LogRotate {
 
         for i in (0..count-1).rev() {
             if self.compress
-                && filenames[i+0].extension().unwrap_or(std::ffi::OsStr::new("")) != "zst"
-                && filenames[i+1].extension().unwrap_or(std::ffi::OsStr::new("")) == "zst"
+                && filenames[i+0].extension() != Some(std::ffi::OsStr::new("zst"))
+                && filenames[i+1].extension() == Some(std::ffi::OsStr::new("zst"))
             {
                 Self::compress(&filenames[i], &filenames[i+1], &options)?;
             } else {
@@ -204,7 +204,7 @@ impl Iterator for LogRotateFiles {
         let filename = self.file_names.next()?;
         let file = File::open(&filename).ok()?;
 
-        if filename.extension().unwrap_or(std::ffi::OsStr::new("")) == "zst" {
+        if filename.extension() == Some(std::ffi::OsStr::new("zst")) {
             let encoder = zstd::stream::read::Decoder::new(file).ok()?;
             return Some(Box::new(encoder));
         }