public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 3/7] apt: use 'apt-get changelog --print-uris' in get_changelog_url
Date: Wed, 21 Oct 2020 11:41:12 +0200	[thread overview]
Message-ID: <20201021094116.32501-4-s.reiter@proxmox.com> (raw)
In-Reply-To: <20201021094116.32501-1-s.reiter@proxmox.com>

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 <s.reiter@proxmox.com>
---
 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 <pkg> --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<String, Error> {
@@ -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 <pkg> --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<F: Fn(FilterData) -> 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





  parent reply	other threads:[~2020-10-21  9:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-21  9:41 [pbs-devel] [PATCH 0/7] apt: add changelog API and fix #2934 (list new packages) Stefan Reiter
2020-10-21  9:41 ` [pbs-devel] [PATCH proxmox-backup 1/7] apt: allow filter to select different package version Stefan Reiter
2020-10-21  9:41 ` [pbs-devel] [PATCH proxmox-backup 2/7] add tools::http for generic HTTP GET and move HttpsConnector there Stefan Reiter
2020-10-21 18:31   ` [pbs-devel] applied: " Thomas Lamprecht
2020-10-21  9:41 ` Stefan Reiter [this message]
2020-10-21  9:41 ` [pbs-devel] [PATCH proxmox-backup 4/7] bump apt-pkg-native dependency to 0.3.2 Stefan Reiter
2020-10-21  9:41 ` [pbs-devel] [PATCH proxmox-backup 5/7] apt: refactor package detail reading into function Stefan Reiter
2020-10-21  9:41 ` [pbs-devel] [PATCH proxmox-backup 6/7] fix #2934: list to-be-installed packages in updates Stefan Reiter
2020-10-21  9:41 ` [pbs-devel] [PATCH proxmox-backup 7/7] apt: add /changelog API call similar to PVE Stefan Reiter
2020-10-22 15:20 ` [pbs-devel] applied-series: [PATCH 0/7] apt: add changelog API and fix #2934 (list new packages) Fabian Grünbichler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201021094116.32501-4-s.reiter@proxmox.com \
    --to=s.reiter@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal