[pbs-devel] [RFC proxmox-backup 1/4] apt: allow filter to select different package version
Stefan Reiter
s.reiter at proxmox.com
Tue Jul 28 10:58:43 CEST 2020
To get package details for a specific version instead of only the
candidate.
Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
src/api2/node/apt.rs | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs
index 37bf48d4..f2c4ae7b 100644
--- a/src/api2/node/apt.rs
+++ b/src/api2/node/apt.rs
@@ -71,7 +71,7 @@ fn get_changelog_url(
bail!("unknown origin ({}) or component ({})", origin, component)
}
-fn list_installed_apt_packages<F: Fn(&str, &str, &str) -> bool>(filter: F)
+fn list_installed_apt_packages<F: Fn(&str, &str, &str, &str) -> bool>(filter: F)
-> Vec<APTUpdateInfo> {
let mut ret = Vec::new();
@@ -99,8 +99,12 @@ fn list_installed_apt_packages<F: Fn(&str, &str, &str) -> bool>(filter: F)
None => current_version.clone()
};
- let package = view.name();
- if filter(&package, ¤t_version, &candidate_version) {
+ // get additional information via nested APT 'iterators'
+ let mut view_iter = view.versions();
+ while let Some(ver) = view_iter.next() {
+
+ let package = view.name();
+ let version = ver.version();
let mut origin_res = "unknown".to_owned();
let mut section_res = "unknown".to_owned();
let mut priority_res = "unknown".to_owned();
@@ -108,9 +112,7 @@ fn list_installed_apt_packages<F: Fn(&str, &str, &str) -> bool>(filter: F)
let mut short_desc = package.clone();
let mut long_desc = "".to_owned();
- // get additional information via nested APT 'iterators'
- let mut view_iter = view.versions();
- while let Some(ver) = view_iter.next() {
+ if filter(&package, ¤t_version, &candidate_version, &version) {
if ver.version() == candidate_version {
if let Some(section) = ver.section() {
section_res = section;
@@ -159,23 +161,21 @@ fn list_installed_apt_packages<F: Fn(&str, &str, &str) -> bool>(filter: F)
}
}
- break;
+ let info = APTUpdateInfo {
+ package,
+ title: short_desc,
+ arch: view.arch(),
+ description: long_desc,
+ change_log_url,
+ origin: origin_res,
+ version: candidate_version.clone(),
+ old_version: current_version.clone(),
+ priority: priority_res,
+ section: section_res,
+ };
+ ret.push(info);
}
}
-
- let info = APTUpdateInfo {
- package,
- title: short_desc,
- arch: view.arch(),
- description: long_desc,
- change_log_url,
- origin: origin_res,
- version: candidate_version,
- old_version: current_version,
- priority: priority_res,
- section: section_res,
- };
- ret.push(info);
}
}
@@ -201,7 +201,7 @@ fn list_installed_apt_packages<F: Fn(&str, &str, &str) -> bool>(filter: F)
)]
/// List available APT updates
fn apt_update_available(_param: Value) -> Result<Value, Error> {
- let ret = list_installed_apt_packages(|_pkg, cur_ver, can_ver| cur_ver != can_ver);
+ let ret = list_installed_apt_packages(|_pkg, cur_ver, can_ver, act_ver| cur_ver != can_ver && can_ver == act_ver);
Ok(json!(ret))
}
--
2.20.1
More information about the pbs-devel
mailing list