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 C9DC190A90 for ; Mon, 30 Jan 2023 12:00:16 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B1C7EE279 for ; Mon, 30 Jan 2023 12:00:16 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 for ; Mon, 30 Jan 2023 12:00:15 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 85F9345453 for ; Mon, 30 Jan 2023 12:00:15 +0100 (CET) From: Leo Nunner To: pve-devel@lists.proxmox.com Date: Mon, 30 Jan 2023 11:59:53 +0100 Message-Id: <20230130105953.126483-1-l.nunner@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.168 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH v2 manager] fix #4481: fetch changelogs for any Proxmox repository X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jan 2023 11:00:16 -0000 This patch fixes the issue that when the user supplied any non-standard repositories, the changelogs often wouldn't load. For example, providing both pve-no-subscription and pbs-no-subscription broke the changelog API, since the URL built for pbs-no-subscription was invalid. Signed-off-by: Leo Nunner --- Changes from v1: - Directly pass $pkgfile to get_changelog_url - Only check enabled repositories - Compare the site of the package with the repository URL PVE/API2/APT.pm | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm index 09c76545..c4e2bb3d 100644 --- a/PVE/API2/APT.pm +++ b/PVE/API2/APT.pm @@ -89,11 +89,16 @@ my $get_pkgfile = sub { }; my $get_changelog_url =sub { - my ($pkgname, $info, $pkgver, $origin, $component) = @_; + my ($pkgname, $info, $pkgver, $pkgfile) = @_; my $changelog_url; my $base; $base = dirname($info->{FileName}) if defined($info->{FileName}); + + my $origin = $pkgfile->{Origin}; + my $component = $pkgfile->{Component}; + my $site = $pkgfile->{Site}; + if ($origin && $base) { $pkgver =~ s/^\d+://; # strip epoch my $srcpkg = $info->{SourcePkg} || $pkgname; @@ -101,10 +106,19 @@ my $get_changelog_url =sub { $base =~ s!pool/updates/!pool/!; # for security channel $changelog_url = "http://packages.debian.org/changelogs/$base/${srcpkg}_${pkgver}/changelog"; } elsif ($origin eq 'Proxmox') { - if ($component eq 'pve-enterprise') { - $changelog_url = "https://enterprise.proxmox.com/debian/$base/${pkgname}_${pkgver}.changelog"; - } else { - $changelog_url = "http://download.proxmox.com/debian/$base/${pkgname}_${pkgver}.changelog"; + my $data = Proxmox::RS::APT::Repositories::repositories("pve"); + + for my $file ($data->{files}->@*) { + for my $repo ($file->{repositories}->@*) { + if ( + $repo->{Enabled} + && grep(/$component/, $repo->{Components}->@*) + && $repo->{URIs}[0] =~ m/$site/ + ) { + $changelog_url = $repo->{URIs}[0] . "/$base/${pkgname}_${pkgver}.changelog"; + last; + } + } } } } @@ -124,7 +138,7 @@ my $assemble_pkginfo = sub { if (my $pkgfile = &$get_pkgfile($candidate_ver)) { $data->{Origin} = $pkgfile->{Origin}; my $changelog_url = $get_changelog_url->( - $pkgname, $info, $candidate_ver->{VerStr}, $pkgfile->{Origin}, $pkgfile->{Component}); + $pkgname, $info, $candidate_ver->{VerStr}, $pkgfile); $data->{ChangeLogUrl} = $changelog_url if $changelog_url; } @@ -431,7 +445,7 @@ __PACKAGE__->register_method({ my $url; die "changelog for '${pkgname}_$ver->{VerStr}' not available\n" - if !($pkgfile && ($url = &$get_changelog_url($pkgname, $info, $ver->{VerStr}, $pkgfile->{Origin}, $pkgfile->{Component}))); + if !($pkgfile && ($url = &$get_changelog_url($pkgname, $info, $ver->{VerStr}, $pkgfile))); my $data = ""; -- 2.30.2