clippy: misc. fixes

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-01-19 11:37:49 +01:00
parent 3f48cdb380
commit ea368a06cd
14 changed files with 23 additions and 28 deletions

View File

@ -212,8 +212,7 @@ pub fn delete_datastore_disk(name: String) -> Result<(), Error> {
let (config, _) = crate::config::datastore::config()?; let (config, _) = crate::config::datastore::config()?;
let datastores: Vec<DataStoreConfig> = config.convert_to_typed_array("datastore")?; let datastores: Vec<DataStoreConfig> = config.convert_to_typed_array("datastore")?;
let conflicting_datastore: Option<DataStoreConfig> = datastores.into_iter() let conflicting_datastore: Option<DataStoreConfig> = datastores.into_iter()
.filter(|ds| ds.path == path) .find(|ds| ds.path == path);
.next();
if let Some(conflicting_datastore) = conflicting_datastore { if let Some(conflicting_datastore) = conflicting_datastore {
bail!("Can't remove '{}' since it's required by datastore '{}'", bail!("Can't remove '{}' since it's required by datastore '{}'",

View File

@ -585,6 +585,7 @@ impl <R: Read + Seek> CatalogReader<R> {
/// ///
/// Stores 7 bits per byte, Bit 8 indicates the end of the sequence (when not set). /// 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). /// If the value is negative, we end with a zero byte (0x00).
#[allow(clippy::neg_multiply)]
pub fn catalog_encode_i64<W: Write>(writer: &mut W, v: i64) -> Result<(), Error> { pub fn catalog_encode_i64<W: Write>(writer: &mut W, v: i64) -> Result<(), Error> {
let mut enc = Vec::new(); let mut enc = Vec::new();
@ -617,6 +618,7 @@ pub fn catalog_encode_i64<W: Write>(writer: &mut W, v: i64) -> Result<(), Error>
/// We currently read maximal 11 bytes, which give a maximum of 70 bits + sign. /// We currently read maximal 11 bytes, which give a maximum of 70 bits + sign.
/// this method is compatible with catalog_encode_u64 iff the /// this method is compatible with catalog_encode_u64 iff the
/// value encoded is <= 2^63 (values > 2^63 cannot be represented in an i64) /// value encoded is <= 2^63 (values > 2^63 cannot be represented in an i64)
#[allow(clippy::neg_multiply)]
pub fn catalog_decode_i64<R: Read>(reader: &mut R) -> Result<i64, Error> { pub fn catalog_decode_i64<R: Read>(reader: &mut R) -> Result<i64, Error> {
let mut v: u64 = 0; let mut v: u64 = 0;

View File

@ -408,9 +408,7 @@ impl <'a, 'b> DataChunkBuilder<'a, 'b> {
chunk_size: usize, chunk_size: usize,
compress: bool, compress: bool,
) -> Result<(DataBlob, [u8; 32]), Error> { ) -> Result<(DataBlob, [u8; 32]), Error> {
let zero_bytes = vec![0; chunk_size];
let mut zero_bytes = Vec::with_capacity(chunk_size);
zero_bytes.resize(chunk_size, 0u8);
let mut chunk_builder = DataChunkBuilder::new(&zero_bytes).compress(compress); let mut chunk_builder = DataChunkBuilder::new(&zero_bytes).compress(compress);
if let Some(ref crypt_config) = crypt_config { if let Some(ref crypt_config) = crypt_config {
chunk_builder = chunk_builder.crypt_config(crypt_config); chunk_builder = chunk_builder.crypt_config(crypt_config);

View File

@ -476,12 +476,11 @@ impl DataStore {
let image_list = self.list_images()?; let image_list = self.list_images()?;
let image_count = image_list.len(); let image_count = image_list.len();
let mut done = 0;
let mut last_percentage: usize = 0; let mut last_percentage: usize = 0;
let mut strange_paths_count: u64 = 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()?; worker.check_abort()?;
tools::fail_on_shutdown()?; tools::fail_on_shutdown()?;
@ -514,15 +513,14 @@ impl DataStore {
Err(err) if err.kind() == io::ErrorKind::NotFound => (), // ignore vanished files Err(err) if err.kind() == io::ErrorKind::NotFound => (), // ignore vanished files
Err(err) => bail!("can't open index {} - {}", img.to_string_lossy(), err), 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 { if percentage > last_percentage {
crate::task_log!( crate::task_log!(
worker, worker,
"marked {}% ({} of {} index files)", "marked {}% ({} of {} index files)",
percentage, percentage,
done, i + 1,
image_count, image_count,
); );
last_percentage = percentage; last_percentage = percentage;

View File

@ -4,7 +4,7 @@ use std::os::unix::io::AsRawFd;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use futures::*; use futures::*;
use hyper;
use openssl::ssl::{SslMethod, SslAcceptor, SslFiletype}; use openssl::ssl::{SslMethod, SslAcceptor, SslFiletype};
use tokio_stream::wrappers::ReceiverStream; use tokio_stream::wrappers::ReceiverStream;

View File

@ -293,7 +293,7 @@ fn test_crypt_speed(
let speed = (bytes as f64)/start_time.elapsed().as_secs_f64(); let speed = (bytes as f64)/start_time.elapsed().as_secs_f64();
benchmark_result.sha256.speed = Some(speed); 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(); 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(); let speed = (bytes as f64)/start_time.elapsed().as_secs_f64();
benchmark_result.compress.speed = Some(speed); 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(); 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(); let speed = (bytes as f64)/start_time.elapsed().as_secs_f64();
benchmark_result.decompress.speed = Some(speed); 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(); 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(); let speed = (bytes as f64)/start_time.elapsed().as_secs_f64();
benchmark_result.aes256_gcm.speed = Some(speed); 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(); 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(); let speed = (bytes as f64)/start_time.elapsed().as_secs_f64();
benchmark_result.verify.speed = Some(speed); 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(()) Ok(())
} }

View File

@ -54,7 +54,7 @@ fn get_tape_handle(param: &Value) -> Result<LinuxTapeHandle, Error> {
let file = unsafe { File::from_raw_fd(fd) }; let file = unsafe { File::from_raw_fd(fd) };
check_tape_is_linux_tape_device(&file)?; check_tape_is_linux_tape_device(&file)?;
LinuxTapeHandle::new(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 (config, _digest) = config::drive::config()?;
let drive: LinuxTapeDrive = config.lookup("linux", &name)?; let drive: LinuxTapeDrive = config.lookup("linux", &name)?;
eprintln!("using device {}", drive.path); eprintln!("using device {}", drive.path);

View File

@ -24,10 +24,7 @@ pub fn has_encryption<F: AsRawFd>(
Ok(data) => data, Ok(data) => data,
Err(_) => return false, Err(_) => return false,
}; };
match decode_spin_data_encryption_caps(&data) { decode_spin_data_encryption_caps(&data).is_ok()
Ok(_) => true,
Err(_) => false,
}
} }
/// Set or clear encryption key /// Set or clear encryption key

View File

@ -17,6 +17,7 @@ bitflags::bitflags!{
/// ///
/// See LTO SCSI Reference LOG_SENSE - LP 2Eh: TapeAlerts /// See LTO SCSI Reference LOG_SENSE - LP 2Eh: TapeAlerts
pub struct TapeAlertFlags: u64 { pub struct TapeAlertFlags: u64 {
#[allow(clippy::eq_op)]
const READ_WARNING = 1 << (0x0001 -1); const READ_WARNING = 1 << (0x0001 -1);
const WRITE_WARNING = 1 << (0x0002 -1); const WRITE_WARNING = 1 << (0x0002 -1);
const HARD_ERROR = 1 << (0x0003 -1); const HARD_ERROR = 1 << (0x0003 -1);

View File

@ -201,7 +201,7 @@ impl <'a, F: AsRawFd> SgRaw<'a, F> {
let data_len = self.buffer.len() - let data_len = self.buffer.len() -
(unsafe { get_scsi_pt_resid(&mut *ptvp) } as usize); (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"); bail!("do_scsi_pt failed - no data received");
} }

View File

@ -144,6 +144,6 @@ fn correct_byte_convert() {
assert_eq!(convert(1023), "1023 B"); assert_eq!(convert(1023), "1023 B");
assert_eq!(convert(1<<10), "1.00 KiB"); assert_eq!(convert(1<<10), "1.00 KiB");
assert_eq!(convert(1<<20), "1.00 MiB"); assert_eq!(convert(1<<20), "1.00 MiB");
assert_eq!(convert((1<<30) + (103 * 1<<20)), "1.10 GiB"); 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((2<<50) + 500 * (1<<40)), "2.49 PiB");
} }

View File

@ -29,7 +29,7 @@ pub fn write_canonical_json(value: &Value, output: &mut Vec<u8>) -> Result<(), E
Value::Object(map) => { Value::Object(map) => {
output.push(b'{'); output.push(b'{');
let mut keys: Vec<&str> = map.keys().map(String::as_str).collect(); let mut keys: Vec<&str> = map.keys().map(String::as_str).collect();
keys.sort(); keys.sort_unstable();
let mut iter = keys.into_iter(); let mut iter = keys.into_iter();
if let Some(key) = iter.next() { if let Some(key) = iter.next() {
serde_json::to_writer(&mut *output, &key)?; serde_json::to_writer(&mut *output, &key)?;

View File

@ -49,7 +49,7 @@ impl DateTimeValue {
} }
pub fn list_contains(list: &[DateTimeValue], value: u32) -> bool { 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 // Find an return an entry greater than value

View File

@ -52,9 +52,9 @@ fn pxar_create_and_extract() {
.unwrap(); .unwrap();
let reader = BufReader::new(stdout); 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; let mut linecount = 0;
while let Some(curr) = line_iter.next() { for curr in line_iter {
println!("{}", curr); println!("{}", curr);
linecount += 1; linecount += 1;
} }