]> git.proxmox.com Git - proxmox-backup.git/commitdiff
clippy: is_some/none/ok/err/empty
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 19 Jan 2021 09:27:59 +0000 (10:27 +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>
22 files changed:
src/api2/access/acl.rs
src/api2/access/user.rs
src/api2/admin/datastore.rs
src/api2/backup/environment.rs
src/api2/config/datastore.rs
src/api2/config/remote.rs
src/api2/config/sync.rs
src/api2/config/verify.rs
src/api2/node/apt.rs
src/api2/node/tasks.rs
src/api2/tape/drive.rs
src/api2/types/mod.rs
src/backup/chunk_store.rs
src/backup/chunk_stream.rs
src/backup/crypt_reader.rs
src/backup/prune.rs
src/bin/proxmox-backup-proxy.rs
src/bin/proxmox_backup_client/mount.rs
src/config/tape_encryption_keys.rs
src/server/worker_task.rs
src/tools/fuse_loop.rs
tests/verify-api.rs

index ff9da46635eb8713e17e7b3d8c1c814c6e120787..f1fd9995ebea8d714bdd5dd04d4e4a1b7ed79723 100644 (file)
@@ -72,7 +72,7 @@ fn extract_acl_node_data(
         }
     }
     for (group, roles) in &node.groups {
-        if let Some(_) = token_user {
+        if token_user.is_some() {
             continue;
         }
 
@@ -210,7 +210,7 @@ pub fn update_acl(
 
     let top_level_privs = user_info.lookup_privs(&current_auth_id, &["access", "acl"]);
     if top_level_privs & PRIV_PERMISSIONS_MODIFY == 0 {
-        if let Some(_) = group {
+        if group.is_some() {
             bail!("Unprivileged users are not allowed to create group ACL item.");
         }
 
index 9af15b69d1679f701f7111b5f8bdf45a8983a664..a4f29f61738b8f727e5b9d7655eef47565b06769 100644 (file)
@@ -230,7 +230,7 @@ pub fn create_user(
 
     let (mut config, _digest) = user::config()?;
 
-    if let Some(_) = config.sections.get(user.userid.as_str()) {
+    if config.sections.get(user.userid.as_str()).is_some() {
         bail!("user '{}' already exists.", user.userid);
     }
 
@@ -595,7 +595,7 @@ pub fn generate_token(
     let tokenid = Authid::from((userid.clone(), Some(tokenname.clone())));
     let tokenid_string = tokenid.to_string();
 
-    if let Some(_) = config.sections.get(&tokenid_string) {
+    if config.sections.get(&tokenid_string).is_some() {
         bail!("token '{}' for user '{}' already exists.", tokenname.as_str(), userid);
     }
 
index cb748194ca9cf47f6e0716b78092004fa8604139..12263e48109245d72c9b750c240831078cdf2980 100644 (file)
@@ -711,7 +711,7 @@ pub fn verify(
 
                 verify_all_backups(datastore, worker.clone(), worker.upid(), owner, None)?
             };
-            if failed_dirs.len() > 0 {
+            if !failed_dirs.is_empty() {
                 worker.log("Failed to verify the following snapshots/groups:");
                 for dir in failed_dirs {
                     worker.log(format!("\t{}", dir));
@@ -1341,7 +1341,7 @@ fn catalog(
 
     if filepath != "root" {
         components = base64::decode(filepath)?;
-        if components.len() > 0 && components[0] == '/' as u8 {
+        if !components.is_empty() && components[0] == b'/' {
             components.remove(0);
         }
         for component in components.split(|c| *c == '/' as u8) {
@@ -1487,7 +1487,7 @@ fn pxar_file_download(
         check_priv_or_backup_owner(&datastore, backup_dir.group(), &auth_id, PRIV_DATASTORE_READ)?;
 
         let mut components = base64::decode(&filepath)?;
-        if components.len() > 0 && components[0] == '/' as u8 {
+        if !components.is_empty() && components[0] == b'/' {
             components.remove(0);
         }
 
index ec7ca55dc6c5e4a4e1aea742df1a497706f7864b..53fd76a2ad7b4638fa96cc86e73a3142fd8cbb05 100644 (file)
@@ -465,7 +465,7 @@ impl BackupEnvironment {
         state.ensure_unfinished()?;
 
         // test if all writer are correctly closed
-        if state.dynamic_writers.len() != 0 || state.fixed_writers.len() != 0 {
+        if !state.dynamic_writers.is_empty() || !state.fixed_writers.is_empty() {
             bail!("found open index writer - unable to finish backup");
         }
 
index b8b420e0809f7033e777c276d2db7abccd5b4206..00009b741f4855363c55cc19ea50427b79d30b3a 100644 (file)
@@ -124,7 +124,7 @@ pub fn create_datastore(param: Value) -> Result<(), Error> {
 
     let (mut config, _digest) = datastore::config()?;
 
-    if let Some(_) = config.sections.get(&datastore.name) {
+    if config.sections.get(&datastore.name).is_some() {
         bail!("datastore '{}' already exists.", datastore.name);
     }
 
index 5c29d28ac0d24f114c48b3e62af74f6a632ebfea..fe7dc451dee218b6fcdcd6762f6a080039eb2c85 100644 (file)
@@ -102,7 +102,7 @@ pub fn create_remote(password: String, param: Value) -> Result<(), Error> {
 
     let (mut config, _digest) = remote::config()?;
 
-    if let Some(_) = config.sections.get(&remote.name) {
+    if config.sections.get(&remote.name).is_some() {
         bail!("remote '{}' already exists.", remote.name);
     }
 
index c0f4090988819e63093041ceafb2e64f169737d1..e7360051db018bf889e01a6136075a617841896d 100644 (file)
@@ -161,7 +161,7 @@ pub fn create_sync_job(
 
     let (mut config, _digest) = sync::config()?;
 
-    if let Some(_) = config.sections.get(&sync_job.id) {
+    if config.sections.get(&sync_job.id).is_some() {
         bail!("job '{}' already exists.", sync_job.id);
     }
 
index 7d59893a0f8d0ed1e88d2a6beb78217c4d794dd3..08a9e7172169ddb65f176022ff836c82c2ffc44b 100644 (file)
@@ -106,7 +106,7 @@ pub fn create_verification_job(
 
     let (mut config, _digest) = verify::config()?;
 
-    if let Some(_) = config.sections.get(&verification_job.id) {
+    if config.sections.get(&verification_job.id).is_some() {
         bail!("job '{}' already exists.", verification_job.id);
     }
 
index 202819195000f1727bbbe0b528eecc04bd8a6667..345b19974a5e9bf16ad350686993574821187343 100644 (file)
@@ -196,7 +196,7 @@ fn apt_get_changelog(
         }
     }, Some(&name));
 
-    if pkg_info.len() == 0 {
+    if pkg_info.is_empty() {
         bail!("Package '{}' not found", name);
     }
 
index 1a9fb9426f46df64b134e91041200a00fb173acc..8de35ca9abeaa7e734c59201a69d2a7c2ecae9ff 100644 (file)
@@ -513,7 +513,7 @@ pub fn list_tasks(
         .collect();
 
     let mut count = result.len() + start as usize;
-    if result.len() > 0 && result.len() >= limit { // we have a 'virtual' entry as long as we have any new
+    if !result.is_empty() && result.len() >= limit { // we have a 'virtual' entry as long as we have any new
         count += 1;
     }
 
index 48b58251849d61ac536b6288ace61dcbb70220cd..ba80f488aeeaf0e08ca72e703cda9d9391b2c409 100644 (file)
@@ -747,11 +747,9 @@ pub fn update_inventory(
 
                 let label_text = label_text.to_string();
 
-                if !read_all_labels.unwrap_or(false) {
-                    if let Some(_) = inventory.find_media_by_label_text(&label_text) {
-                        worker.log(format!("media '{}' already inventoried", label_text));
-                        continue;
-                    }
+                if !read_all_labels.unwrap_or(false) && inventory.find_media_by_label_text(&label_text).is_some() {
+                    worker.log(format!("media '{}' already inventoried", label_text));
+                    continue;
                 }
 
                 if let Err(err) = changer.load_media(&label_text) {
index 718753248b55cbe42776b441c16b76040be45ae6..7cb1cdcef5e5dadc32bfe237082e78e553ba69cf 100644 (file)
@@ -1077,7 +1077,7 @@ fn test_cert_fingerprint_schema() -> Result<(), anyhow::Error> {
     ];
 
     for fingerprint in invalid_fingerprints.iter() {
-        if let Ok(_) = parse_simple_value(fingerprint, &schema) {
+        if parse_simple_value(fingerprint, &schema).is_ok() {
             bail!("test fingerprint '{}' failed -  got Ok() while exception an error.", fingerprint);
         }
     }
@@ -1118,7 +1118,7 @@ fn test_proxmox_user_id_schema() -> Result<(), anyhow::Error> {
     ];
 
     for name in invalid_user_ids.iter() {
-        if let Ok(_) = parse_simple_value(name, &Userid::API_SCHEMA) {
+        if parse_simple_value(name, &Userid::API_SCHEMA).is_ok() {
             bail!("test userid '{}' failed -  got Ok() while exception an error.", name);
         }
     }
index 99d62a2efb9cbfadba30f98d2748c48307ed471c..39635d7d6d302042875131a12b2a5683c02c37dd 100644 (file)
@@ -401,7 +401,7 @@ impl ChunkStore {
         file.write_all(raw_data)?;
 
         if let Err(err) = std::fs::rename(&tmp_path, &chunk_path) {
-            if let Err(_) = std::fs::remove_file(&tmp_path)  { /* ignore */ }
+            if std::fs::remove_file(&tmp_path).is_err()  { /* ignore */ }
             bail!(
                 "Atomic rename on store '{}' failed for chunk {} - {}",
                 self.name,
index 5bb061583df2439ede2d661836d71f447fadc7fc..2c4040c4db34935e00944b3cf7c6dda4e3a884fe 100644 (file)
@@ -59,7 +59,7 @@ where
                 }
                 None => {
                     this.scan_pos = 0;
-                    if this.buffer.len() > 0 {
+                    if !this.buffer.is_empty() {
                         return Poll::Ready(Some(Ok(this.buffer.split())));
                     } else {
                         return Poll::Ready(None);
@@ -111,7 +111,7 @@ where
                 }
                 None => {
                     // last chunk can have any size
-                    if this.buffer.len() > 0 {
+                    if !this.buffer.is_empty() {
                         return Poll::Ready(Some(Ok(this.buffer.split())));
                     } else {
                         return Poll::Ready(None);
index ee2e625a69415dd5894bcec30f08eeb12dae118f..8bf15cfdee4575ff9203f404576ad4360b77d9e3 100644 (file)
@@ -36,7 +36,7 @@ impl <R: BufRead> CryptReader<R> {
 impl <R: BufRead> Read for CryptReader<R> {
 
     fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
-        if self.small_read_buf.len() > 0 {
+        if !self.small_read_buf.is_empty() {
             let max = if self.small_read_buf.len() > buf.len() {  buf.len() } else { self.small_read_buf.len() };
             let rest = self.small_read_buf.split_off(max);
             buf[..max].copy_from_slice(&self.small_read_buf);
@@ -50,7 +50,7 @@ impl <R: BufRead> Read for CryptReader<R> {
         if buf.len() <= 2*self.block_size {
             let mut outbuf = [0u8; 1024];
 
-            let count = if data.len() == 0 { // EOF
+            let count = if data.is_empty() { // EOF
                 let written = self.crypter.finalize(&mut outbuf)?;
                 self.finalized = true;
                 written
@@ -72,7 +72,7 @@ impl <R: BufRead> Read for CryptReader<R> {
                 buf[..count].copy_from_slice(&outbuf[..count]);
                 Ok(count)
             }
-        } else if data.len() == 0 { // EOF
+        } else if data.is_empty() { // EOF
             let rest = self.crypter.finalize(buf)?;
             self.finalized = true;
             Ok(rest)
index bc0a75ad6513effe4d90499f2435a0eb9a38a927..66c2ee84c26d1d41cd3e3d16b5f65bf5c9446639 100644 (file)
@@ -26,7 +26,7 @@ fn mark_selections<F: Fn(&BackupInfo) -> Result<String, Error>> (
 
     for info in list {
         let backup_id = info.backup_dir.relative_path();
-        if let Some(_) = mark.get(&backup_id) { continue; }
+        if mark.get(&backup_id).is_some() { continue; }
         let sel_id: String = select_id(&info)?;
 
         if already_included.contains(&sel_id) { continue; }
index 39e8d537b143688df015ff10ac07ff963d3e5bca..53bd526b999c91013ad9ac00b538111c5f4ee279 100644 (file)
@@ -218,10 +218,8 @@ fn accept_connections(
 
                         match result {
                             Ok(Ok(())) => {
-                                if let Err(_) = sender.send(Ok(stream)).await {
-                                    if debug {
-                                        eprintln!("detect closed connection channel");
-                                    }
+                                if sender.send(Ok(stream)).await.is_err() && debug {
+                                    eprintln!("detect closed connection channel");
                                 }
                             }
                             Ok(Err(err)) => {
index f8410709df844167dcf055bd9864b176d4397a2e..72ed9166bef07c56035afdac9cdfb2dbe98726d4 100644 (file)
@@ -189,12 +189,12 @@ async fn mount_do(param: Value, pipe: Option<Fd>) -> Result<Value, Error> {
     };
 
     let server_archive_name = if archive_name.ends_with(".pxar") {
-        if let None = target {
+        if target.is_none() {
             bail!("use the 'mount' command to mount pxar archives");
         }
         format!("{}.didx", archive_name)
     } else if archive_name.ends_with(".img") {
-        if let Some(_) = target {
+        if target.is_some() {
             bail!("use the 'map' command to map drive images");
         }
         format!("{}.fidx", archive_name)
index 284d0ed3110c5ec01307c865fe6858771055df03..64e533ecb7488fa73471e29b970a29f5dc0b1e79 100644 (file)
@@ -219,7 +219,7 @@ pub fn insert_key(key: [u8;32], key_config: KeyConfig, hint: String) -> Result<(
         None => bail!("missing encryption key fingerprint - internal error"),
     };
 
-    if let Some(_) = config_map.get(&fingerprint) {
+    if config_map.get(&fingerprint).is_some() {
         bail!("encryption key '{}' already exists.", fingerprint);
     }
 
index f047c347eada776bbce84ede6c3a6f18d80eda4a..0d884ba194f717e723c7665854e0ef89e81a64bb 100644 (file)
@@ -48,7 +48,7 @@ pub async fn worker_is_active(upid: &UPID) -> Result<bool, Error> {
         return Ok(WORKER_TASK_LIST.lock().unwrap().contains_key(&upid.task_id));
     }
 
-    if !procfs::check_process_running_pstart(upid.pid, upid.pstart).is_some() {
+    if procfs::check_process_running_pstart(upid.pid, upid.pstart).is_none() {
         return Ok(false);
     }
 
@@ -191,7 +191,7 @@ pub fn upid_read_status(upid: &UPID) -> Result<TaskState, Error> {
     file.read_to_end(&mut data)?;
 
     // task logs should end with newline, we do not want it here
-    if data.len() > 0 && data[data.len()-1] == b'\n' {
+    if !data.is_empty() && data[data.len()-1] == b'\n' {
         data.pop();
     }
 
@@ -270,7 +270,7 @@ impl TaskState {
         } else if let Some(warnings) = s.strip_prefix("WARNINGS: ") {
             let count: u64 = warnings.parse()?;
             Ok(TaskState::Warning{ count, endtime })
-        } else if s.len() > 0 {
+        } else if !s.is_empty() {
             let message = if let Some(err) = s.strip_prefix("ERROR: ") { err } else { s }.to_string();
             Ok(TaskState::Error{ message, endtime })
         } else {
index 8a8b668a0f0c5d527d4041f8e76e4e2d4edad725..ebc30398bf4d2c23845ecaba1134ba8465a3fa22 100644 (file)
@@ -113,7 +113,7 @@ impl<R: AsyncRead + AsyncSeek + Unpin> FuseLoopSession<R> {
         abort_chan: Receiver<()>,
     ) -> Result<(), Error> {
 
-        if let None = self.session {
+        if self.session.is_none() {
             panic!("internal error: fuse_loop::main called before ::map_loop");
         }
         let mut session = self.session.take().unwrap().fuse();
@@ -236,7 +236,7 @@ pub fn cleanup_unused_run_files(filter_name: Option<String>) {
 
                 // clean leftover FUSE instances (e.g. user called 'losetup -d' or similar)
                 // does nothing if files are already stagnant (e.g. instance crashed etc...)
-                if let Ok(_) = unmap_from_backing(&path, None) {
+                if unmap_from_backing(&path, None).is_ok() {
                     // we have reaped some leftover instance, tell the user
                     eprintln!(
                         "Cleaned up dangling mapping '{}': no loop device assigned",
index 83a26a215de299533300b99bf4f1f9f41f53d773..0d6b654b16ec17cdcab2a299eb28ff74bb09097d 100644 (file)
@@ -13,7 +13,7 @@ fn verify_object_schema(schema: &ObjectSchema) -> Result<(), Error> {
 
     let map = schema.properties;
 
-    if map.len() >= 1 {
+    if !map.is_empty() {
 
         for i in 1..map.len() {
 
@@ -125,7 +125,7 @@ fn verify_dirmap(
     dirmap: SubdirMap,
 ) -> Result<(), Error> {
 
-    if dirmap.len() >= 1 {
+    if !dirmap.is_empty() {
 
         for i in 1..dirmap.len() {