clippy: collapse nested ifs

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-01-19 11:06:26 +01:00
parent 3b82f3eea5
commit 6334bdc1c5
10 changed files with 52 additions and 74 deletions

View File

@ -1051,11 +1051,9 @@ pub fn catalog_media(
let _lock = MediaPool::lock(status_path, &pool)?; let _lock = MediaPool::lock(status_path, &pool)?;
if MediaCatalog::exists(status_path, &media_id.label.uuid) { if MediaCatalog::exists(status_path, &media_id.label.uuid) && !force {
if !force {
bail!("media catalog exists (please use --force to overwrite)"); bail!("media catalog exists (please use --force to overwrite)");
} }
}
restore_media(&worker, &mut drive, &media_id, None, verbose)?; restore_media(&worker, &mut drive, &media_id, None, verbose)?;

View File

@ -359,16 +359,12 @@ fn restore_chunk_archive<'a>(
worker.log(format!("Insert chunk: {}", proxmox::tools::digest_to_hex(&digest))); worker.log(format!("Insert chunk: {}", proxmox::tools::digest_to_hex(&digest)));
} }
datastore.insert_chunk(&blob, &digest)?; datastore.insert_chunk(&blob, &digest)?;
} else { } else if verbose {
if verbose {
worker.log(format!("Found existing chunk: {}", proxmox::tools::digest_to_hex(&digest))); worker.log(format!("Found existing chunk: {}", proxmox::tools::digest_to_hex(&digest)));
} }
} } else if verbose {
} else {
if verbose {
worker.log(format!("Found chunk: {}", proxmox::tools::digest_to_hex(&digest))); worker.log(format!("Found chunk: {}", proxmox::tools::digest_to_hex(&digest)));
} }
}
chunks.push(digest); chunks.push(digest);
} }
None => break, None => break,

View File

@ -601,8 +601,7 @@ fn debug_scan(param: Value) -> Result<(), Error> {
Ok(header) => { Ok(header) => {
if header.magic != PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0 { if header.magic != PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0 {
println!("got MediaContentHeader with wrong magic: {:?}", header.magic); println!("got MediaContentHeader with wrong magic: {:?}", header.magic);
} else { } else if let Some(name) = PROXMOX_BACKUP_CONTENT_NAME.get(&header.content_magic) {
if let Some(name) = PROXMOX_BACKUP_CONTENT_NAME.get(&header.content_magic) {
println!("got content header: {}", name); println!("got content header: {}", name);
println!(" uuid: {}", header.content_uuid()); println!(" uuid: {}", header.content_uuid());
println!(" ctime: {}", strftime_local("%c", header.ctime)?); println!(" ctime: {}", strftime_local("%c", header.ctime)?);
@ -612,7 +611,6 @@ fn debug_scan(param: Value) -> Result<(), Error> {
println!("got unknown content header: {:?}", header.content_magic); println!("got unknown content header: {:?}", header.content_magic);
} }
} }
}
Err(err) => { Err(err) => {
println!("unable to read content header - {}", err); println!("unable to read content header - {}", err);
} }

View File

@ -274,14 +274,12 @@ fn main() -> Result<(), Error> {
bail!("this program needs to be run with setuid root"); bail!("this program needs to be run with setuid root");
} }
if !running_uid.is_root() { if !running_uid.is_root() && (running_uid != backup_uid || running_gid != backup_gid) {
if running_uid != backup_uid || running_gid != backup_gid {
bail!( bail!(
"Not running as backup user or group (got uid {} gid {})", "Not running as backup user or group (got uid {} gid {})",
running_uid, running_gid, running_uid, running_gid,
); );
} }
}
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert( .insert(

View File

@ -187,14 +187,12 @@ pub trait MediaChange {
if let ElementStatus::Empty = element_status { if let ElementStatus::Empty = element_status {
to = Some(i as u64 + 1); to = Some(i as u64 + 1);
} }
} else { } else if let ElementStatus::VolumeTag(ref tag) = element_status {
if let ElementStatus::VolumeTag(ref tag) = element_status {
if tag == label_text { if tag == label_text {
from = Some(i as u64 + 1); from = Some(i as u64 + 1);
} }
} }
} }
}
if unload_from_drive { if unload_from_drive {
match to { match to {

View File

@ -97,8 +97,7 @@ impl LinuxTapeDrive {
if drive_status.blocksize == 0 { if drive_status.blocksize == 0 {
// device is variable block size - OK // device is variable block size - OK
} else { } else if drive_status.blocksize != PROXMOX_TAPE_BLOCK_SIZE as u32 {
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!("device is in fixed block size mode with wrong size ({} bytes)", drive_status.blocksize);
eprintln!("trying to set variable block size mode..."); eprintln!("trying to set variable block size mode...");
if handle.set_block_size(0).is_err() { if handle.set_block_size(0).is_err() {
@ -107,7 +106,6 @@ impl LinuxTapeDrive {
} else { } else {
// device is in fixed block size mode with correct block size // device is in fixed block size mode with correct block size
} }
}
// Only root can set driver options, so we cannot // Only root can set driver options, so we cannot
// handle.set_default_options()?; // handle.set_default_options()?;

View File

@ -378,8 +378,7 @@ pub fn request_and_load_media(
media_id.label.uuid.to_string(), media_id.label.uuid.to_string(),
)); ));
return Ok((Box::new(handle), media_id)); return Ok((Box::new(handle), media_id));
} else { } else if Some(media_id.label.uuid.clone()) != last_media_uuid {
if Some(media_id.label.uuid.clone()) != last_media_uuid {
worker.log(format!( worker.log(format!(
"wrong media label {} ({})", "wrong media label {} ({})",
media_id.label.label_text, media_id.label.label_text,
@ -388,7 +387,6 @@ pub fn request_and_load_media(
last_media_uuid = Some(media_id.label.uuid); last_media_uuid = Some(media_id.label.uuid);
} }
} }
}
Ok((None, _)) => { Ok((None, _)) => {
if last_media_uuid.is_some() { if last_media_uuid.is_some() {
worker.log("found empty media without label (please label all tapes first)".to_string()); worker.log("found empty media without label (please label all tapes first)".to_string());

View File

@ -81,11 +81,9 @@ impl <R: Read> BlockedReader<R> {
if size > buffer.payload.len() { if size > buffer.payload.len() {
proxmox::io_bail!("detected tape block with wrong payload size ({} > {}", size, buffer.payload.len()); proxmox::io_bail!("detected tape block with wrong payload size ({} > {}", size, buffer.payload.len());
} else if size == 0 { } else if size == 0 && !found_end_marker {
if !found_end_marker{
proxmox::io_bail!("detected tape block with zero payload size"); proxmox::io_bail!("detected tape block with zero payload size");
} }
}
Ok((size, found_end_marker)) Ok((size, found_end_marker))

View File

@ -675,8 +675,7 @@ impl Inventory {
for (uuid, entry) in self.map.iter_mut() { for (uuid, entry) in self.map.iter_mut() {
if let Some(changer_name) = online_map.lookup_changer(uuid) { if let Some(changer_name) = online_map.lookup_changer(uuid) {
entry.location = Some(MediaLocation::Online(changer_name.to_string())); entry.location = Some(MediaLocation::Online(changer_name.to_string()));
} else { } else if let Some(MediaLocation::Online(ref changer_name)) = entry.location {
if let Some(MediaLocation::Online(ref changer_name)) = entry.location {
match online_map.online_map(changer_name) { match online_map.online_map(changer_name) {
None => { None => {
// no such changer device // no such changer device
@ -692,7 +691,6 @@ impl Inventory {
} }
} }
} }
}
self.update_helpers(); self.update_helpers();
self.replace_file()?; self.replace_file()?;

View File

@ -159,12 +159,10 @@ impl PoolWriter {
} }
} }
} else { } else if let Some(mut status) = status {
if let Some(mut status) = status {
worker.log("standalone drive - ejecting media instead of export"); worker.log("standalone drive - ejecting media instead of export");
status.drive.eject_media()?; status.drive.eject_media()?;
} }
}
Ok(()) Ok(())
} }