apt: refactor package detail reading into function
No functional change intended. Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
parent
1872050564
commit
52d2ae48f0
|
@ -90,19 +90,39 @@ fn list_installed_apt_packages<F: Fn(FilterData) -> bool>(filter: F)
|
||||||
let mut cache_iter = cache.iter();
|
let mut cache_iter = cache.iter();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let view = match cache_iter.next() {
|
|
||||||
Some(view) => view,
|
|
||||||
None => break
|
|
||||||
};
|
|
||||||
|
|
||||||
|
match cache_iter.next() {
|
||||||
|
Some(view) => {
|
||||||
|
let di = query_detailed_info(&filter, view);
|
||||||
|
if let Some(info) = di {
|
||||||
|
ret.push(info);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn query_detailed_info<'a, F, V>(
|
||||||
|
filter: F,
|
||||||
|
view: V,
|
||||||
|
) -> Option<APTUpdateInfo>
|
||||||
|
where
|
||||||
|
F: Fn(FilterData) -> bool,
|
||||||
|
V: std::ops::Deref<Target = apt_pkg_native::sane::PkgView<'a>>
|
||||||
|
{
|
||||||
let current_version = view.current_version();
|
let current_version = view.current_version();
|
||||||
let candidate_version = view.candidate_version();
|
let candidate_version = view.candidate_version();
|
||||||
|
|
||||||
let (current_version, candidate_version) = match (current_version, candidate_version) {
|
let (current_version, candidate_version) = match (current_version, candidate_version) {
|
||||||
(Some(cur), Some(can)) => (cur, can), // package installed and there is an update
|
(Some(cur), Some(can)) => (cur, can), // package installed and there is an update
|
||||||
(Some(cur), None) => (cur.clone(), cur), // package installed and up-to-date
|
(Some(cur), None) => (cur.clone(), cur), // package installed and up-to-date
|
||||||
(None, Some(_)) => continue, // package could be installed
|
(None, Some(_)) => return None, // package could be installed
|
||||||
(None, None) => continue, // broken
|
(None, None) => return None, // broken
|
||||||
};
|
};
|
||||||
|
|
||||||
// get additional information via nested APT 'iterators'
|
// get additional information via nested APT 'iterators'
|
||||||
|
@ -172,7 +192,7 @@ fn list_installed_apt_packages<F: Fn(FilterData) -> bool>(filter: F)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let info = APTUpdateInfo {
|
return Some(APTUpdateInfo {
|
||||||
package,
|
package,
|
||||||
title: short_desc,
|
title: short_desc,
|
||||||
arch: view.arch(),
|
arch: view.arch(),
|
||||||
|
@ -183,13 +203,11 @@ fn list_installed_apt_packages<F: Fn(FilterData) -> bool>(filter: F)
|
||||||
old_version: current_version.clone(),
|
old_version: current_version.clone(),
|
||||||
priority: priority_res,
|
priority: priority_res,
|
||||||
section: section_res,
|
section: section_res,
|
||||||
};
|
});
|
||||||
ret.push(info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
|
|
Loading…
Reference in New Issue