From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 4992D616F6 for ; Wed, 21 Oct 2020 11:42:04 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6D19716962 for ; Wed, 21 Oct 2020 11:41:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id D094E16855 for ; Wed, 21 Oct 2020 11:41:29 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 973AA45E98 for ; Wed, 21 Oct 2020 11:41:29 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Wed, 21 Oct 2020 11:41:14 +0200 Message-Id: <20201021094116.32501-6-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201021094116.32501-1-s.reiter@proxmox.com> References: <20201021094116.32501-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.031 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [apt.rs] Subject: [pbs-devel] [PATCH proxmox-backup 5/7] apt: refactor package detail reading into function X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Oct 2020 09:42:04 -0000 No functional change intended. Signed-off-by: Stefan Reiter --- src/api2/node/apt.rs | 204 +++++++++++++++++++++++-------------------- 1 file changed, 111 insertions(+), 93 deletions(-) diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs index b120eef5..d8a2e824 100644 --- a/src/api2/node/apt.rs +++ b/src/api2/node/apt.rs @@ -90,101 +90,16 @@ fn list_installed_apt_packages bool>(filter: F) let mut cache_iter = cache.iter(); loop { - let view = match cache_iter.next() { - Some(view) => view, - None => break - }; - let current_version = view.current_version(); - let candidate_version = view.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), None) => (cur.clone(), cur), // package installed and up-to-date - (None, Some(_)) => continue, // package could be installed - (None, None) => continue, // broken - }; - - // 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(); - let mut change_log_url = "".to_owned(); - let mut short_desc = package.clone(); - let mut long_desc = "".to_owned(); - - let fd = FilterData { - installed_version: ¤t_version, - candidate_version: &candidate_version, - active_version: &version, - }; - - if filter(fd) { - if let Some(section) = ver.section() { - section_res = section; + match cache_iter.next() { + Some(view) => { + let di = query_detailed_info(&filter, view); + if let Some(info) = di { + ret.push(info); } - - if let Some(prio) = ver.priority_type() { - priority_res = prio; - } - - // assume every package has only one origin file (not - // origin, but origin *file*, for some reason those seem to - // be different concepts in APT) - let mut origin_iter = ver.origin_iter(); - let origin = origin_iter.next(); - if let Some(origin) = origin { - - if let Some(sd) = origin.short_desc() { - short_desc = sd; - } - - if let Some(ld) = origin.long_desc() { - long_desc = ld; - } - - // the package files appear in priority order, meaning - // the one for the candidate version is first - this is fine - // however, as the source package should be the same for all - // versions anyway - let mut pkg_iter = origin.file(); - let pkg_file = pkg_iter.next(); - if let Some(pkg_file) = pkg_file { - if let Some(origin_name) = pkg_file.origin() { - origin_res = origin_name; - } - - let filename = pkg_file.file_name(); - let component = pkg_file.component(); - - // build changelog URL from gathered information - // ignore errors, use empty changelog instead - let url = get_changelog_url(&package, &filename, - &version, &origin_res, &component); - if let Ok(url) = url { - change_log_url = url; - } - } - } - - 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); + }, + None => { + break; } } } @@ -192,6 +107,109 @@ fn list_installed_apt_packages bool>(filter: F) return ret; } +fn query_detailed_info<'a, F, V>( + filter: F, + view: V, +) -> Option +where + F: Fn(FilterData) -> bool, + V: std::ops::Deref> +{ + let current_version = view.current_version(); + let candidate_version = view.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), None) => (cur.clone(), cur), // package installed and up-to-date + (None, Some(_)) => return None, // package could be installed + (None, None) => return None, // broken + }; + + // 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(); + let mut change_log_url = "".to_owned(); + let mut short_desc = package.clone(); + let mut long_desc = "".to_owned(); + + let fd = FilterData { + installed_version: ¤t_version, + candidate_version: &candidate_version, + active_version: &version, + }; + + if filter(fd) { + if let Some(section) = ver.section() { + section_res = section; + } + + if let Some(prio) = ver.priority_type() { + priority_res = prio; + } + + // assume every package has only one origin file (not + // origin, but origin *file*, for some reason those seem to + // be different concepts in APT) + let mut origin_iter = ver.origin_iter(); + let origin = origin_iter.next(); + if let Some(origin) = origin { + + if let Some(sd) = origin.short_desc() { + short_desc = sd; + } + + if let Some(ld) = origin.long_desc() { + long_desc = ld; + } + + // the package files appear in priority order, meaning + // the one for the candidate version is first - this is fine + // however, as the source package should be the same for all + // versions anyway + let mut pkg_iter = origin.file(); + let pkg_file = pkg_iter.next(); + if let Some(pkg_file) = pkg_file { + if let Some(origin_name) = pkg_file.origin() { + origin_res = origin_name; + } + + let filename = pkg_file.file_name(); + let component = pkg_file.component(); + + // build changelog URL from gathered information + // ignore errors, use empty changelog instead + let url = get_changelog_url(&package, &filename, + &version, &origin_res, &component); + if let Ok(url) = url { + change_log_url = url; + } + } + } + + return Some(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, + }); + } + } + + return None; +} + #[api( input: { properties: { -- 2.20.1