From ea368a06cd4e2041c705d0232923ce70346ddb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 19 Jan 2021 11:37:49 +0100 Subject: [PATCH] clippy: misc. fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Grünbichler --- src/api2/node/disks/directory.rs | 3 +-- src/backup/catalog.rs | 2 ++ src/backup/data_blob.rs | 4 +--- src/backup/datastore.rs | 8 +++----- src/bin/proxmox-backup-proxy.rs | 2 +- src/bin/proxmox_backup_client/benchmark.rs | 10 +++++----- src/bin/sg-tape-cmd.rs | 2 +- src/tape/drive/encryption.rs | 5 +---- src/tape/drive/tape_alert_flags.rs | 1 + src/tape/sgutils2.rs | 2 +- src/tools/format.rs | 4 ++-- src/tools/json.rs | 2 +- src/tools/systemd/time.rs | 2 +- tests/pxar.rs | 4 ++-- 14 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs index c3840526..c968b333 100644 --- a/src/api2/node/disks/directory.rs +++ b/src/api2/node/disks/directory.rs @@ -212,8 +212,7 @@ pub fn delete_datastore_disk(name: String) -> Result<(), Error> { let (config, _) = crate::config::datastore::config()?; let datastores: Vec = config.convert_to_typed_array("datastore")?; let conflicting_datastore: Option = datastores.into_iter() - .filter(|ds| ds.path == path) - .next(); + .find(|ds| ds.path == path); if let Some(conflicting_datastore) = conflicting_datastore { bail!("Can't remove '{}' since it's required by datastore '{}'", diff --git a/src/backup/catalog.rs b/src/backup/catalog.rs index 4c72ba3a..224e6bf7 100644 --- a/src/backup/catalog.rs +++ b/src/backup/catalog.rs @@ -585,6 +585,7 @@ impl CatalogReader { /// /// Stores 7 bits per byte, Bit 8 indicates the end of the sequence (when not set). /// If the value is negative, we end with a zero byte (0x00). +#[allow(clippy::neg_multiply)] pub fn catalog_encode_i64(writer: &mut W, v: i64) -> Result<(), Error> { let mut enc = Vec::new(); @@ -617,6 +618,7 @@ pub fn catalog_encode_i64(writer: &mut W, v: i64) -> Result<(), Error> /// We currently read maximal 11 bytes, which give a maximum of 70 bits + sign. /// this method is compatible with catalog_encode_u64 iff the /// value encoded is <= 2^63 (values > 2^63 cannot be represented in an i64) +#[allow(clippy::neg_multiply)] pub fn catalog_decode_i64(reader: &mut R) -> Result { let mut v: u64 = 0; diff --git a/src/backup/data_blob.rs b/src/backup/data_blob.rs index 284dc243..2c36ac9a 100644 --- a/src/backup/data_blob.rs +++ b/src/backup/data_blob.rs @@ -408,9 +408,7 @@ impl <'a, 'b> DataChunkBuilder<'a, 'b> { chunk_size: usize, compress: bool, ) -> Result<(DataBlob, [u8; 32]), Error> { - - let mut zero_bytes = Vec::with_capacity(chunk_size); - zero_bytes.resize(chunk_size, 0u8); + let zero_bytes = vec![0; chunk_size]; let mut chunk_builder = DataChunkBuilder::new(&zero_bytes).compress(compress); if let Some(ref crypt_config) = crypt_config { chunk_builder = chunk_builder.crypt_config(crypt_config); diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index de129135..b1099460 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -476,12 +476,11 @@ impl DataStore { let image_list = self.list_images()?; let image_count = image_list.len(); - let mut done = 0; let mut last_percentage: usize = 0; let mut strange_paths_count: u64 = 0; - for img in image_list { + for (i, img) in image_list.into_iter().enumerate() { worker.check_abort()?; tools::fail_on_shutdown()?; @@ -514,15 +513,14 @@ impl DataStore { Err(err) if err.kind() == io::ErrorKind::NotFound => (), // ignore vanished files Err(err) => bail!("can't open index {} - {}", img.to_string_lossy(), err), } - done += 1; - let percentage = done*100/image_count; + let percentage = (i + 1) * 100 / image_count; if percentage > last_percentage { crate::task_log!( worker, "marked {}% ({} of {} index files)", percentage, - done, + i + 1, image_count, ); last_percentage = percentage; diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 92f6f67c..0cfd56d5 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -4,7 +4,7 @@ use std::os::unix::io::AsRawFd; use anyhow::{bail, format_err, Error}; use futures::*; -use hyper; + use openssl::ssl::{SslMethod, SslAcceptor, SslFiletype}; use tokio_stream::wrappers::ReceiverStream; diff --git a/src/bin/proxmox_backup_client/benchmark.rs b/src/bin/proxmox_backup_client/benchmark.rs index 2ecb3dc9..1076dc19 100644 --- a/src/bin/proxmox_backup_client/benchmark.rs +++ b/src/bin/proxmox_backup_client/benchmark.rs @@ -293,7 +293,7 @@ fn test_crypt_speed( let speed = (bytes as f64)/start_time.elapsed().as_secs_f64(); benchmark_result.sha256.speed = Some(speed); - eprintln!("SHA256 speed: {:.2} MB/s", speed/1_000_000_.0); + eprintln!("SHA256 speed: {:.2} MB/s", speed/1_000_000.0); let start_time = std::time::Instant::now(); @@ -308,7 +308,7 @@ fn test_crypt_speed( let speed = (bytes as f64)/start_time.elapsed().as_secs_f64(); benchmark_result.compress.speed = Some(speed); - eprintln!("Compression speed: {:.2} MB/s", speed/1_000_000_.0); + eprintln!("Compression speed: {:.2} MB/s", speed/1_000_000.0); let start_time = std::time::Instant::now(); @@ -328,7 +328,7 @@ fn test_crypt_speed( let speed = (bytes as f64)/start_time.elapsed().as_secs_f64(); benchmark_result.decompress.speed = Some(speed); - eprintln!("Decompress speed: {:.2} MB/s", speed/1_000_000_.0); + eprintln!("Decompress speed: {:.2} MB/s", speed/1_000_000.0); let start_time = std::time::Instant::now(); @@ -343,7 +343,7 @@ fn test_crypt_speed( let speed = (bytes as f64)/start_time.elapsed().as_secs_f64(); benchmark_result.aes256_gcm.speed = Some(speed); - eprintln!("AES256/GCM speed: {:.2} MB/s", speed/1_000_000_.0); + eprintln!("AES256/GCM speed: {:.2} MB/s", speed/1_000_000.0); let start_time = std::time::Instant::now(); @@ -361,7 +361,7 @@ fn test_crypt_speed( let speed = (bytes as f64)/start_time.elapsed().as_secs_f64(); benchmark_result.verify.speed = Some(speed); - eprintln!("Verify speed: {:.2} MB/s", speed/1_000_000_.0); + eprintln!("Verify speed: {:.2} MB/s", speed/1_000_000.0); Ok(()) } diff --git a/src/bin/sg-tape-cmd.rs b/src/bin/sg-tape-cmd.rs index b6145660..fa89e5ef 100644 --- a/src/bin/sg-tape-cmd.rs +++ b/src/bin/sg-tape-cmd.rs @@ -54,7 +54,7 @@ fn get_tape_handle(param: &Value) -> Result { let file = unsafe { File::from_raw_fd(fd) }; check_tape_is_linux_tape_device(&file)?; LinuxTapeHandle::new(file) - } else if let Some(name) = std::env::var("PROXMOX_TAPE_DRIVE").ok() { + } else if let Ok(name) = std::env::var("PROXMOX_TAPE_DRIVE") { let (config, _digest) = config::drive::config()?; let drive: LinuxTapeDrive = config.lookup("linux", &name)?; eprintln!("using device {}", drive.path); diff --git a/src/tape/drive/encryption.rs b/src/tape/drive/encryption.rs index 4b08dfd1..77d05567 100644 --- a/src/tape/drive/encryption.rs +++ b/src/tape/drive/encryption.rs @@ -24,10 +24,7 @@ pub fn has_encryption( Ok(data) => data, Err(_) => return false, }; - match decode_spin_data_encryption_caps(&data) { - Ok(_) => true, - Err(_) => false, - } + decode_spin_data_encryption_caps(&data).is_ok() } /// Set or clear encryption key diff --git a/src/tape/drive/tape_alert_flags.rs b/src/tape/drive/tape_alert_flags.rs index 8d19ea02..3ce5b658 100644 --- a/src/tape/drive/tape_alert_flags.rs +++ b/src/tape/drive/tape_alert_flags.rs @@ -17,6 +17,7 @@ bitflags::bitflags!{ /// /// See LTO SCSI Reference LOG_SENSE - LP 2Eh: TapeAlerts pub struct TapeAlertFlags: u64 { + #[allow(clippy::eq_op)] const READ_WARNING = 1 << (0x0001 -1); const WRITE_WARNING = 1 << (0x0002 -1); const HARD_ERROR = 1 << (0x0003 -1); diff --git a/src/tape/sgutils2.rs b/src/tape/sgutils2.rs index 464acbd9..31cd61b5 100644 --- a/src/tape/sgutils2.rs +++ b/src/tape/sgutils2.rs @@ -201,7 +201,7 @@ impl <'a, F: AsRawFd> SgRaw<'a, F> { let data_len = self.buffer.len() - (unsafe { get_scsi_pt_resid(&mut *ptvp) } as usize); - if data_len <= 0 { + if data_len == 0 { bail!("do_scsi_pt failed - no data received"); } diff --git a/src/tools/format.rs b/src/tools/format.rs index c9f50053..70d0490b 100644 --- a/src/tools/format.rs +++ b/src/tools/format.rs @@ -144,6 +144,6 @@ fn correct_byte_convert() { assert_eq!(convert(1023), "1023 B"); assert_eq!(convert(1<<10), "1.00 KiB"); assert_eq!(convert(1<<20), "1.00 MiB"); - assert_eq!(convert((1<<30) + (103 * 1<<20)), "1.10 GiB"); - assert_eq!(convert((2<<50) + (500 * 1<<40)), "2.49 PiB"); + assert_eq!(convert((1<<30) + 103 * (1<<20)), "1.10 GiB"); + assert_eq!(convert((2<<50) + 500 * (1<<40)), "2.49 PiB"); } diff --git a/src/tools/json.rs b/src/tools/json.rs index c81afccb..7a43c700 100644 --- a/src/tools/json.rs +++ b/src/tools/json.rs @@ -29,7 +29,7 @@ pub fn write_canonical_json(value: &Value, output: &mut Vec) -> Result<(), E Value::Object(map) => { output.push(b'{'); let mut keys: Vec<&str> = map.keys().map(String::as_str).collect(); - keys.sort(); + keys.sort_unstable(); let mut iter = keys.into_iter(); if let Some(key) = iter.next() { serde_json::to_writer(&mut *output, &key)?; diff --git a/src/tools/systemd/time.rs b/src/tools/systemd/time.rs index 1961d4b8..02395724 100644 --- a/src/tools/systemd/time.rs +++ b/src/tools/systemd/time.rs @@ -49,7 +49,7 @@ impl DateTimeValue { } pub fn list_contains(list: &[DateTimeValue], value: u32) -> bool { - list.iter().find(|spec| spec.contains(value)).is_some() + list.iter().any(|spec| spec.contains(value)) } // Find an return an entry greater than value diff --git a/tests/pxar.rs b/tests/pxar.rs index cdb25e3f..03181c7f 100644 --- a/tests/pxar.rs +++ b/tests/pxar.rs @@ -52,9 +52,9 @@ fn pxar_create_and_extract() { .unwrap(); let reader = BufReader::new(stdout); - let mut line_iter = reader.lines().map(|l| l.unwrap()); + let line_iter = reader.lines().map(|l| l.unwrap()); let mut linecount = 0; - while let Some(curr) = line_iter.next() { + for curr in line_iter { println!("{}", curr); linecount += 1; }