clippy: convert single match to if let

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-01-19 12:09:33 +01:00
parent ea368a06cd
commit b92cad0938
7 changed files with 66 additions and 88 deletions

View File

@ -35,13 +35,10 @@ use crate::api2::types::{Authid, APTUpdateInfo, NODE_SCHEMA, UPID_SCHEMA};
/// List available APT updates /// List available APT updates
fn apt_update_available(_param: Value) -> Result<Value, Error> { fn apt_update_available(_param: Value) -> Result<Value, Error> {
match apt::pkg_cache_expired() { if let Ok(false) = apt::pkg_cache_expired() {
Ok(false) => {
if let Ok(Some(cache)) = apt::read_pkg_state() { if let Ok(Some(cache)) = apt::read_pkg_state() {
return Ok(json!(cache.package_status)); return Ok(json!(cache.package_status));
} }
},
_ => (),
} }
let cache = apt::update_cache()?; let cache = apt::update_cache()?;

View File

@ -127,8 +127,7 @@ fn datastore_status(
rrd_mode, rrd_mode,
); );
match (total_res, used_res) { if let (Some((start, reso, total_list)), Some((_, _, used_list))) = (total_res, used_res) {
(Some((start, reso, total_list)), Some((_, _, used_list))) => {
let mut usage_list: Vec<f64> = Vec::new(); let mut usage_list: Vec<f64> = Vec::new();
let mut time_list: Vec<u64> = Vec::new(); let mut time_list: Vec<u64> = Vec::new();
let mut history = Vec::new(); let mut history = Vec::new();
@ -168,8 +167,6 @@ fn datastore_status(
} }
} }
} }
},
_ => {},
} }
list.push(entry); list.push(entry);

View File

@ -39,13 +39,12 @@ pub fn do_garbage_collection_job(
let status = worker.create_state(&result); let status = worker.create_state(&result);
match job.finish(status) { if let Err(err) = job.finish(status) {
Err(err) => eprintln!( eprintln!(
"could not finish job state for {}: {}", "could not finish job state for {}: {}",
job.jobtype().to_string(), job.jobtype().to_string(),
err err
), );
Ok(_) => (),
} }
if let Some(email) = email { if let Some(email) = email {

View File

@ -207,12 +207,9 @@ impl Job {
/// Start the job and update the statefile accordingly /// Start the job and update the statefile accordingly
/// Fails if the job was already started /// Fails if the job was already started
pub fn start(&mut self, upid: &str) -> Result<(), Error> { pub fn start(&mut self, upid: &str) -> Result<(), Error> {
match self.state { if let JobState::Started { .. } = self.state {
JobState::Started { .. } => {
bail!("cannot start job that is started!"); bail!("cannot start job that is started!");
} }
_ => {}
}
self.state = JobState::Started { self.state = JobState::Started {
upid: upid.to_string(), upid: upid.to_string(),

View File

@ -83,13 +83,12 @@ pub fn do_verification_job(
let status = worker.create_state(&job_result); let status = worker.create_state(&job_result);
match job.finish(status) { if let Err(err) = job.finish(status) {
Err(err) => eprintln!( eprintln!(
"could not finish job state for {}: {}", "could not finish job state for {}: {}",
job.jobtype().to_string(), job.jobtype().to_string(),
err err
), );
Ok(_) => (),
} }
if let Some(email) = email { if let Some(email) = email {

View File

@ -566,8 +566,7 @@ pub fn get_partition_type_info() -> Result<HashMap<String, Vec<String>>, Error>
let mut res: HashMap<String, Vec<String>> = HashMap::new(); let mut res: HashMap<String, Vec<String>> = HashMap::new();
let output: serde_json::Value = output.parse()?; let output: serde_json::Value = output.parse()?;
match output["blockdevices"].as_array() { if let Some(list) = output["blockdevices"].as_array() {
Some(list) => {
for info in list { for info in list {
let path = match info["path"].as_str() { let path = match info["path"].as_str() {
Some(p) => p, Some(p) => p,
@ -581,10 +580,6 @@ pub fn get_partition_type_info() -> Result<HashMap<String, Vec<String>>, Error>
devices.push(path.to_string()); devices.push(path.to_string());
} }
} }
None => {
}
}
Ok(res) Ok(res)
} }

View File

@ -357,18 +357,12 @@ pub fn find_all_mappings() -> Result<impl Iterator<Item = (String, Option<String
// get map of all /dev/loop mappings belonging to us // get map of all /dev/loop mappings belonging to us
let mut loopmap = HashMap::new(); let mut loopmap = HashMap::new();
for ent in fs::scan_subdir(libc::AT_FDCWD, Path::new("/dev/"), &LOOPDEV_REGEX)? { for ent in fs::scan_subdir(libc::AT_FDCWD, Path::new("/dev/"), &LOOPDEV_REGEX)? {
match ent { if let Ok(ent) = ent {
Ok(ent) => {
let loopdev = format!("/dev/{}", ent.file_name().to_string_lossy()); let loopdev = format!("/dev/{}", ent.file_name().to_string_lossy());
match get_backing_file(&loopdev) { if let Ok(file) = get_backing_file(&loopdev) {
Ok(file) => {
// insert filename only, strip RUN_DIR/ // insert filename only, strip RUN_DIR/
loopmap.insert(file[RUN_DIR.len()+1..].to_owned(), loopdev); loopmap.insert(file[RUN_DIR.len()+1..].to_owned(), loopdev);
},
Err(_) => {},
} }
},
Err(_) => {},
} }
} }