From 6334bdc1c5451b72c067c5c1c996d6e3991fd4b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 19 Jan 2021 11:06:26 +0100 Subject: [PATCH] clippy: collapse nested ifs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Grünbichler --- src/api2/tape/drive.rs | 6 ++---- src/api2/tape/restore.rs | 12 ++++-------- src/bin/proxmox-tape.rs | 16 +++++++--------- src/bin/sg-tape-cmd.rs | 12 +++++------- src/tape/changer/mod.rs | 8 +++----- src/tape/drive/linux_tape.rs | 16 +++++++--------- src/tape/drive/mod.rs | 16 +++++++--------- src/tape/helpers/blocked_reader.rs | 6 ++---- src/tape/inventory.rs | 26 ++++++++++++-------------- src/tape/pool_writer.rs | 8 +++----- 10 files changed, 52 insertions(+), 74 deletions(-) diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index 4571d9e2..3a0b79ce 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -1051,10 +1051,8 @@ pub fn catalog_media( let _lock = MediaPool::lock(status_path, &pool)?; - if MediaCatalog::exists(status_path, &media_id.label.uuid) { - if !force { - bail!("media catalog exists (please use --force to overwrite)"); - } + if MediaCatalog::exists(status_path, &media_id.label.uuid) && !force { + bail!("media catalog exists (please use --force to overwrite)"); } restore_media(&worker, &mut drive, &media_id, None, verbose)?; diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs index e97ae4a4..1db64077 100644 --- a/src/api2/tape/restore.rs +++ b/src/api2/tape/restore.rs @@ -359,15 +359,11 @@ fn restore_chunk_archive<'a>( worker.log(format!("Insert chunk: {}", proxmox::tools::digest_to_hex(&digest))); } datastore.insert_chunk(&blob, &digest)?; - } else { - if verbose { - worker.log(format!("Found existing chunk: {}", proxmox::tools::digest_to_hex(&digest))); - } - } - } else { - if verbose { - worker.log(format!("Found chunk: {}", proxmox::tools::digest_to_hex(&digest))); + } else if verbose { + worker.log(format!("Found existing chunk: {}", proxmox::tools::digest_to_hex(&digest))); } + } else if verbose { + worker.log(format!("Found chunk: {}", proxmox::tools::digest_to_hex(&digest))); } chunks.push(digest); } diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index 09dd25b1..7995977d 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -601,16 +601,14 @@ fn debug_scan(param: Value) -> Result<(), Error> { Ok(header) => { if header.magic != PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0 { println!("got MediaContentHeader with wrong magic: {:?}", header.magic); + } else if let Some(name) = PROXMOX_BACKUP_CONTENT_NAME.get(&header.content_magic) { + println!("got content header: {}", name); + println!(" uuid: {}", header.content_uuid()); + println!(" ctime: {}", strftime_local("%c", header.ctime)?); + println!(" hsize: {}", HumanByte::from(header.size as usize)); + println!(" part: {}", header.part_number); } else { - if let Some(name) = PROXMOX_BACKUP_CONTENT_NAME.get(&header.content_magic) { - println!("got content header: {}", name); - println!(" uuid: {}", header.content_uuid()); - println!(" ctime: {}", strftime_local("%c", header.ctime)?); - println!(" hsize: {}", HumanByte::from(header.size as usize)); - println!(" part: {}", header.part_number); - } else { - println!("got unknown content header: {:?}", header.content_magic); - } + println!("got unknown content header: {:?}", header.content_magic); } } Err(err) => { diff --git a/src/bin/sg-tape-cmd.rs b/src/bin/sg-tape-cmd.rs index d63f595f..b6145660 100644 --- a/src/bin/sg-tape-cmd.rs +++ b/src/bin/sg-tape-cmd.rs @@ -274,13 +274,11 @@ fn main() -> Result<(), Error> { bail!("this program needs to be run with setuid root"); } - if !running_uid.is_root() { - if running_uid != backup_uid || running_gid != backup_gid { - bail!( - "Not running as backup user or group (got uid {} gid {})", - running_uid, running_gid, - ); - } + if !running_uid.is_root() && (running_uid != backup_uid || running_gid != backup_gid) { + bail!( + "Not running as backup user or group (got uid {} gid {})", + running_uid, running_gid, + ); } let cmd_def = CliCommandMap::new() diff --git a/src/tape/changer/mod.rs b/src/tape/changer/mod.rs index 6e2c5b5b..6e92bbe2 100644 --- a/src/tape/changer/mod.rs +++ b/src/tape/changer/mod.rs @@ -187,11 +187,9 @@ pub trait MediaChange { if let ElementStatus::Empty = element_status { to = Some(i as u64 + 1); } - } else { - if let ElementStatus::VolumeTag(ref tag) = element_status { - if tag == label_text { - from = Some(i as u64 + 1); - } + } else if let ElementStatus::VolumeTag(ref tag) = element_status { + if tag == label_text { + from = Some(i as u64 + 1); } } } diff --git a/src/tape/drive/linux_tape.rs b/src/tape/drive/linux_tape.rs index fab8a2ca..02da7e37 100644 --- a/src/tape/drive/linux_tape.rs +++ b/src/tape/drive/linux_tape.rs @@ -97,16 +97,14 @@ impl LinuxTapeDrive { if drive_status.blocksize == 0 { // device is variable block size - OK - } else { - if drive_status.blocksize != PROXMOX_TAPE_BLOCK_SIZE as u32 { - eprintln!("device is in fixed block size mode with wrong size ({} bytes)", drive_status.blocksize); - eprintln!("trying to set variable block size mode..."); - if handle.set_block_size(0).is_err() { - bail!("set variable block size mod failed - device uses wrong blocksize."); - } - } else { - // device is in fixed block size mode with correct block size + } else if drive_status.blocksize != PROXMOX_TAPE_BLOCK_SIZE as u32 { + eprintln!("device is in fixed block size mode with wrong size ({} bytes)", drive_status.blocksize); + eprintln!("trying to set variable block size mode..."); + if handle.set_block_size(0).is_err() { + bail!("set variable block size mod failed - device uses wrong blocksize."); } + } else { + // device is in fixed block size mode with correct block size } // Only root can set driver options, so we cannot diff --git a/src/tape/drive/mod.rs b/src/tape/drive/mod.rs index 6f6b6f75..3f9271e4 100644 --- a/src/tape/drive/mod.rs +++ b/src/tape/drive/mod.rs @@ -378,15 +378,13 @@ pub fn request_and_load_media( media_id.label.uuid.to_string(), )); return Ok((Box::new(handle), media_id)); - } else { - if Some(media_id.label.uuid.clone()) != last_media_uuid { - worker.log(format!( - "wrong media label {} ({})", - media_id.label.label_text, - media_id.label.uuid.to_string(), - )); - last_media_uuid = Some(media_id.label.uuid); - } + } else if Some(media_id.label.uuid.clone()) != last_media_uuid { + worker.log(format!( + "wrong media label {} ({})", + media_id.label.label_text, + media_id.label.uuid.to_string(), + )); + last_media_uuid = Some(media_id.label.uuid); } } Ok((None, _)) => { diff --git a/src/tape/helpers/blocked_reader.rs b/src/tape/helpers/blocked_reader.rs index 821d2ceb..e4f875b6 100644 --- a/src/tape/helpers/blocked_reader.rs +++ b/src/tape/helpers/blocked_reader.rs @@ -81,10 +81,8 @@ impl BlockedReader { if size > buffer.payload.len() { proxmox::io_bail!("detected tape block with wrong payload size ({} > {}", size, buffer.payload.len()); - } else if size == 0 { - if !found_end_marker{ - proxmox::io_bail!("detected tape block with zero payload size"); - } + } else if size == 0 && !found_end_marker { + proxmox::io_bail!("detected tape block with zero payload size"); } diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs index 21b72e0a..17832c21 100644 --- a/src/tape/inventory.rs +++ b/src/tape/inventory.rs @@ -675,20 +675,18 @@ impl Inventory { for (uuid, entry) in self.map.iter_mut() { if let Some(changer_name) = online_map.lookup_changer(uuid) { entry.location = Some(MediaLocation::Online(changer_name.to_string())); - } else { - if let Some(MediaLocation::Online(ref changer_name)) = entry.location { - match online_map.online_map(changer_name) { - None => { - // no such changer device - entry.location = Some(MediaLocation::Offline); - } - Some(None) => { - // got no info - do nothing - } - Some(Some(_)) => { - // media changer changed - entry.location = Some(MediaLocation::Offline); - } + } else if let Some(MediaLocation::Online(ref changer_name)) = entry.location { + match online_map.online_map(changer_name) { + None => { + // no such changer device + entry.location = Some(MediaLocation::Offline); + } + Some(None) => { + // got no info - do nothing + } + Some(Some(_)) => { + // media changer changed + entry.location = Some(MediaLocation::Offline); } } } diff --git a/src/tape/pool_writer.rs b/src/tape/pool_writer.rs index 4486d644..57f6c648 100644 --- a/src/tape/pool_writer.rs +++ b/src/tape/pool_writer.rs @@ -159,11 +159,9 @@ impl PoolWriter { } } - } else { - if let Some(mut status) = status { - worker.log("standalone drive - ejecting media instead of export"); - status.drive.eject_media()?; - } + } else if let Some(mut status) = status { + worker.log("standalone drive - ejecting media instead of export"); + status.drive.eject_media()?; } Ok(())