From 3984a5fd776a579a2eed0a04026014610b0edd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 19 Jan 2021 10:27:59 +0100 Subject: [PATCH] clippy: is_some/none/ok/err/empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Grünbichler --- src/api2/access/acl.rs | 4 ++-- src/api2/access/user.rs | 4 ++-- src/api2/admin/datastore.rs | 6 +++--- src/api2/backup/environment.rs | 2 +- src/api2/config/datastore.rs | 2 +- src/api2/config/remote.rs | 2 +- src/api2/config/sync.rs | 2 +- src/api2/config/verify.rs | 2 +- src/api2/node/apt.rs | 2 +- src/api2/node/tasks.rs | 2 +- src/api2/tape/drive.rs | 8 +++----- src/api2/types/mod.rs | 4 ++-- src/backup/chunk_store.rs | 2 +- src/backup/chunk_stream.rs | 4 ++-- src/backup/crypt_reader.rs | 6 +++--- src/backup/prune.rs | 2 +- src/bin/proxmox-backup-proxy.rs | 6 ++---- src/bin/proxmox_backup_client/mount.rs | 4 ++-- src/config/tape_encryption_keys.rs | 2 +- src/server/worker_task.rs | 6 +++--- src/tools/fuse_loop.rs | 4 ++-- tests/verify-api.rs | 4 ++-- 22 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/api2/access/acl.rs b/src/api2/access/acl.rs index ff9da466..f1fd9995 100644 --- a/src/api2/access/acl.rs +++ b/src/api2/access/acl.rs @@ -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(¤t_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."); } diff --git a/src/api2/access/user.rs b/src/api2/access/user.rs index 9af15b69..a4f29f61 100644 --- a/src/api2/access/user.rs +++ b/src/api2/access/user.rs @@ -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); } diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index cb748194..12263e48 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -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); } diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs index ec7ca55d..53fd76a2 100644 --- a/src/api2/backup/environment.rs +++ b/src/api2/backup/environment.rs @@ -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"); } diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index b8b420e0..00009b74 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -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); } diff --git a/src/api2/config/remote.rs b/src/api2/config/remote.rs index 5c29d28a..fe7dc451 100644 --- a/src/api2/config/remote.rs +++ b/src/api2/config/remote.rs @@ -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); } diff --git a/src/api2/config/sync.rs b/src/api2/config/sync.rs index c0f40909..e7360051 100644 --- a/src/api2/config/sync.rs +++ b/src/api2/config/sync.rs @@ -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); } diff --git a/src/api2/config/verify.rs b/src/api2/config/verify.rs index 7d59893a..08a9e717 100644 --- a/src/api2/config/verify.rs +++ b/src/api2/config/verify.rs @@ -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); } diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs index 20281919..345b1997 100644 --- a/src/api2/node/apt.rs +++ b/src/api2/node/apt.rs @@ -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); } diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs index 1a9fb942..8de35ca9 100644 --- a/src/api2/node/tasks.rs +++ b/src/api2/node/tasks.rs @@ -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; } diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index 48b58251..ba80f488 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -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) { diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index 71875324..7cb1cdce 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -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); } } diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index 99d62a2e..39635d7d 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -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, diff --git a/src/backup/chunk_stream.rs b/src/backup/chunk_stream.rs index 5bb06158..2c4040c4 100644 --- a/src/backup/chunk_stream.rs +++ b/src/backup/chunk_stream.rs @@ -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); diff --git a/src/backup/crypt_reader.rs b/src/backup/crypt_reader.rs index ee2e625a..8bf15cfd 100644 --- a/src/backup/crypt_reader.rs +++ b/src/backup/crypt_reader.rs @@ -36,7 +36,7 @@ impl CryptReader { impl Read for CryptReader { fn read(&mut self, buf: &mut [u8]) -> Result { - 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 Read for CryptReader { 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 Read for CryptReader { 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) diff --git a/src/backup/prune.rs b/src/backup/prune.rs index bc0a75ad..66c2ee84 100644 --- a/src/backup/prune.rs +++ b/src/backup/prune.rs @@ -26,7 +26,7 @@ fn mark_selections Result> ( 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; } diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 39e8d537..53bd526b 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -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)) => { diff --git a/src/bin/proxmox_backup_client/mount.rs b/src/bin/proxmox_backup_client/mount.rs index f8410709..72ed9166 100644 --- a/src/bin/proxmox_backup_client/mount.rs +++ b/src/bin/proxmox_backup_client/mount.rs @@ -189,12 +189,12 @@ async fn mount_do(param: Value, pipe: Option) -> Result { }; 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) diff --git a/src/config/tape_encryption_keys.rs b/src/config/tape_encryption_keys.rs index 284d0ed3..64e533ec 100644 --- a/src/config/tape_encryption_keys.rs +++ b/src/config/tape_encryption_keys.rs @@ -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); } diff --git a/src/server/worker_task.rs b/src/server/worker_task.rs index f047c347..0d884ba1 100644 --- a/src/server/worker_task.rs +++ b/src/server/worker_task.rs @@ -48,7 +48,7 @@ pub async fn worker_is_active(upid: &UPID) -> Result { 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 { 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 { diff --git a/src/tools/fuse_loop.rs b/src/tools/fuse_loop.rs index 8a8b668a..ebc30398 100644 --- a/src/tools/fuse_loop.rs +++ b/src/tools/fuse_loop.rs @@ -113,7 +113,7 @@ impl FuseLoopSession { 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) { // 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", diff --git a/tests/verify-api.rs b/tests/verify-api.rs index 83a26a21..0d6b654b 100644 --- a/tests/verify-api.rs +++ b/tests/verify-api.rs @@ -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() {