clippy: convert single match to if let
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
ea368a06cd
commit
b92cad0938
@ -35,13 +35,10 @@ use crate::api2::types::{Authid, APTUpdateInfo, NODE_SCHEMA, UPID_SCHEMA};
|
||||
/// List available APT updates
|
||||
fn apt_update_available(_param: Value) -> Result<Value, Error> {
|
||||
|
||||
match apt::pkg_cache_expired() {
|
||||
Ok(false) => {
|
||||
if let Ok(Some(cache)) = apt::read_pkg_state() {
|
||||
return Ok(json!(cache.package_status));
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
if let Ok(false) = apt::pkg_cache_expired() {
|
||||
if let Ok(Some(cache)) = apt::read_pkg_state() {
|
||||
return Ok(json!(cache.package_status));
|
||||
}
|
||||
}
|
||||
|
||||
let cache = apt::update_cache()?;
|
||||
|
@ -127,49 +127,46 @@ fn datastore_status(
|
||||
rrd_mode,
|
||||
);
|
||||
|
||||
match (total_res, used_res) {
|
||||
(Some((start, reso, total_list)), Some((_, _, used_list))) => {
|
||||
let mut usage_list: Vec<f64> = Vec::new();
|
||||
let mut time_list: Vec<u64> = Vec::new();
|
||||
let mut history = Vec::new();
|
||||
if let (Some((start, reso, total_list)), Some((_, _, used_list))) = (total_res, used_res) {
|
||||
let mut usage_list: Vec<f64> = Vec::new();
|
||||
let mut time_list: Vec<u64> = Vec::new();
|
||||
let mut history = Vec::new();
|
||||
|
||||
for (idx, used) in used_list.iter().enumerate() {
|
||||
let total = if idx < total_list.len() {
|
||||
total_list[idx]
|
||||
for (idx, used) in used_list.iter().enumerate() {
|
||||
let total = if idx < total_list.len() {
|
||||
total_list[idx]
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
match (total, used) {
|
||||
(Some(total), Some(used)) if total != 0.0 => {
|
||||
time_list.push(start + (idx as u64)*reso);
|
||||
let usage = used/total;
|
||||
usage_list.push(usage);
|
||||
history.push(json!(usage));
|
||||
},
|
||||
_ => {
|
||||
history.push(json!(null))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entry["history-start"] = start.into();
|
||||
entry["history-delta"] = reso.into();
|
||||
entry["history"] = history.into();
|
||||
|
||||
// we skip the calculation for datastores with not enough data
|
||||
if usage_list.len() >= 7 {
|
||||
if let Some((a,b)) = linear_regression(&time_list, &usage_list) {
|
||||
if b != 0.0 {
|
||||
let estimate = (1.0 - a) / b;
|
||||
entry["estimated-full-date"] = Value::from(estimate.floor() as u64);
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
match (total, used) {
|
||||
(Some(total), Some(used)) if total != 0.0 => {
|
||||
time_list.push(start + (idx as u64)*reso);
|
||||
let usage = used/total;
|
||||
usage_list.push(usage);
|
||||
history.push(json!(usage));
|
||||
},
|
||||
_ => {
|
||||
history.push(json!(null))
|
||||
}
|
||||
entry["estimated-full-date"] = Value::from(0);
|
||||
}
|
||||
}
|
||||
|
||||
entry["history-start"] = start.into();
|
||||
entry["history-delta"] = reso.into();
|
||||
entry["history"] = history.into();
|
||||
|
||||
// we skip the calculation for datastores with not enough data
|
||||
if usage_list.len() >= 7 {
|
||||
if let Some((a,b)) = linear_regression(&time_list, &usage_list) {
|
||||
if b != 0.0 {
|
||||
let estimate = (1.0 - a) / b;
|
||||
entry["estimated-full-date"] = Value::from(estimate.floor() as u64);
|
||||
} else {
|
||||
entry["estimated-full-date"] = Value::from(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
list.push(entry);
|
||||
|
@ -39,13 +39,12 @@ pub fn do_garbage_collection_job(
|
||||
|
||||
let status = worker.create_state(&result);
|
||||
|
||||
match job.finish(status) {
|
||||
Err(err) => eprintln!(
|
||||
if let Err(err) = job.finish(status) {
|
||||
eprintln!(
|
||||
"could not finish job state for {}: {}",
|
||||
job.jobtype().to_string(),
|
||||
err
|
||||
),
|
||||
Ok(_) => (),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(email) = email {
|
||||
|
@ -207,11 +207,8 @@ impl Job {
|
||||
/// Start the job and update the statefile accordingly
|
||||
/// Fails if the job was already started
|
||||
pub fn start(&mut self, upid: &str) -> Result<(), Error> {
|
||||
match self.state {
|
||||
JobState::Started { .. } => {
|
||||
bail!("cannot start job that is started!");
|
||||
}
|
||||
_ => {}
|
||||
if let JobState::Started { .. } = self.state {
|
||||
bail!("cannot start job that is started!");
|
||||
}
|
||||
|
||||
self.state = JobState::Started {
|
||||
|
@ -83,13 +83,12 @@ pub fn do_verification_job(
|
||||
|
||||
let status = worker.create_state(&job_result);
|
||||
|
||||
match job.finish(status) {
|
||||
Err(err) => eprintln!(
|
||||
if let Err(err) = job.finish(status) {
|
||||
eprintln!(
|
||||
"could not finish job state for {}: {}",
|
||||
job.jobtype().to_string(),
|
||||
err
|
||||
),
|
||||
Ok(_) => (),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(email) = email {
|
||||
|
@ -566,23 +566,18 @@ pub fn get_partition_type_info() -> Result<HashMap<String, Vec<String>>, Error>
|
||||
let mut res: HashMap<String, Vec<String>> = HashMap::new();
|
||||
|
||||
let output: serde_json::Value = output.parse()?;
|
||||
match output["blockdevices"].as_array() {
|
||||
Some(list) => {
|
||||
for info in list {
|
||||
let path = match info["path"].as_str() {
|
||||
Some(p) => p,
|
||||
None => continue,
|
||||
};
|
||||
let partition_type = match info["parttype"].as_str() {
|
||||
Some(t) => t.to_owned(),
|
||||
None => continue,
|
||||
};
|
||||
let devices = res.entry(partition_type).or_insert(Vec::new());
|
||||
devices.push(path.to_string());
|
||||
}
|
||||
}
|
||||
None => {
|
||||
|
||||
if let Some(list) = output["blockdevices"].as_array() {
|
||||
for info in list {
|
||||
let path = match info["path"].as_str() {
|
||||
Some(p) => p,
|
||||
None => continue,
|
||||
};
|
||||
let partition_type = match info["parttype"].as_str() {
|
||||
Some(t) => t.to_owned(),
|
||||
None => continue,
|
||||
};
|
||||
let devices = res.entry(partition_type).or_insert(Vec::new());
|
||||
devices.push(path.to_string());
|
||||
}
|
||||
}
|
||||
Ok(res)
|
||||
|
@ -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
|
||||
let mut loopmap = HashMap::new();
|
||||
for ent in fs::scan_subdir(libc::AT_FDCWD, Path::new("/dev/"), &LOOPDEV_REGEX)? {
|
||||
match ent {
|
||||
Ok(ent) => {
|
||||
let loopdev = format!("/dev/{}", ent.file_name().to_string_lossy());
|
||||
match get_backing_file(&loopdev) {
|
||||
Ok(file) => {
|
||||
// insert filename only, strip RUN_DIR/
|
||||
loopmap.insert(file[RUN_DIR.len()+1..].to_owned(), loopdev);
|
||||
},
|
||||
Err(_) => {},
|
||||
}
|
||||
},
|
||||
Err(_) => {},
|
||||
if let Ok(ent) = ent {
|
||||
let loopdev = format!("/dev/{}", ent.file_name().to_string_lossy());
|
||||
if let Ok(file) = get_backing_file(&loopdev) {
|
||||
// insert filename only, strip RUN_DIR/
|
||||
loopmap.insert(file[RUN_DIR.len()+1..].to_owned(), loopdev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user