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 D30FD61721 for ; Wed, 21 Oct 2020 11:41:30 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C92BE16856 for ; Wed, 21 Oct 2020 11:41:30 +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 069AF16839 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 B9FD145E98 for ; Wed, 21 Oct 2020 11:41:28 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Wed, 21 Oct 2020 11:41:12 +0200 Message-Id: <20201021094116.32501-4-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.034 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_SHORT 0.001 Use of a URL Shortener for very short URL 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, foo.com] Subject: [pbs-devel] [PATCH proxmox-backup 3/7] apt: use 'apt-get changelog --print-uris' in get_changelog_url 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:41:30 -0000 Avoids custom hardcoded logic, but can only be used for debian packages as of now. Adds a FIXME to switch over to use --print-uris only once our package repos support that changelog format. Signed-off-by: Stefan Reiter --- src/api2/node/apt.rs | 46 ++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs index 40791126..b120eef5 100644 --- a/src/api2/node/apt.rs +++ b/src/api2/node/apt.rs @@ -16,14 +16,13 @@ const_regex! { FILENAME_EXTRACT_REGEX = r"^.*/.*?_(.*)_Packages$"; } -// FIXME: Replace with call to 'apt changelog --print-uris'. Currently -// not possible as our packages do not have a URI set in their Release file +// FIXME: once the 'changelog' API call switches over to 'apt-get changelog' only, +// consider removing this function entirely, as it's value is never used anywhere +// then (widget-toolkit doesn't use the value either) fn get_changelog_url( package: &str, filename: &str, - source_pkg: &str, version: &str, - source_version: &str, origin: &str, component: &str, ) -> Result { @@ -32,25 +31,24 @@ fn get_changelog_url( } if origin == "Debian" { - let source_version = (VERSION_EPOCH_REGEX.regex_obj)().replace_all(source_version, ""); - - let prefix = if source_pkg.starts_with("lib") { - source_pkg.get(0..4) - } else { - source_pkg.get(0..1) + let mut command = std::process::Command::new("apt-get"); + command.arg("changelog"); + command.arg("--print-uris"); + command.arg(package); + let output = crate::tools::run_command(command, None)?; // format: 'http://foo/bar' package.changelog + let output = match output.splitn(2, ' ').next() { + Some(output) => { + if output.len() < 2 { + bail!("invalid output (URI part too short) from 'apt-get changelog --print-uris: {}", output) + } + output[1..output.len()-1].to_owned() + }, + None => bail!("invalid output from 'apt-get changelog --print-uris': {}", output) }; - - let prefix = match prefix { - Some(p) => p, - None => bail!("cannot get starting characters of package name '{}'", package) - }; - - // note: security updates seem to not always upload a changelog for - // their package version, so this only works *most* of the time - return Ok(format!("https://metadata.ftp-master.debian.org/changelogs/main/{}/{}/{}_{}_changelog", - prefix, source_pkg, source_pkg, source_version)); - + return Ok(output); } else if origin == "Proxmox" { + // FIXME: Use above call to 'apt changelog --print-uris' as well. + // Currently not possible as our packages do not have a URI set in their Release file. let version = (VERSION_EPOCH_REGEX.regex_obj)().replace_all(version, ""); let base = match (FILENAME_EXTRACT_REGEX.regex_obj)().captures(filename) { @@ -162,14 +160,12 @@ fn list_installed_apt_packages bool>(filter: F) } let filename = pkg_file.file_name(); - let source_pkg = ver.source_package(); - let source_ver = ver.source_version(); let component = pkg_file.component(); // build changelog URL from gathered information // ignore errors, use empty changelog instead - let url = get_changelog_url(&package, &filename, &source_pkg, - &version, &source_ver, &origin_res, &component); + let url = get_changelog_url(&package, &filename, + &version, &origin_res, &component); if let Ok(url) = url { change_log_url = url; } -- 2.20.1