Subject: bug#58697: [bug] guix refresh nftables crashes

From: 宋文武 <[email-masked]>
Date: Mon, 24 Oct 2022 16:44:02 +0800

Maxime Devos <[email-masked]> writes:

> On 22-10-2022 03:55, kiasoc5 via Bug reports for GNU Guix wrote:
>> % guix refresh nftables
>> [...]
>> ice-9/boot-9.scm:1685:16: In procedure raise-exception:
>> In procedure getaddrinfo: Servname not supported for ai_socktype
>> ```
>
> I can reproduce this locally and don't know the cause.
>

It happens when the origin have both 'mirror://' and 'http://' urls,
current the html updater check for any url match 'http' or 'https', but
when updating it will just pick the first url, so when the first is
'mirror://' this error will come.

This patch should fix it:

>From e9dfdc3a2031c25043cc8b6f4b08656d05024c16 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= <[email-masked]>
Date: Mon, 24 Oct 2022 16:35:18 +0800
Subject: [PATCH] gnu-maintenance: Don't try html updater on 'mirror://' urls.

This fixes <https://issues.guix.gnu.org/58697>.

* guix/gnu-maintenance.scm (latest-html-updatable-release): Use the first http
or https url for updating.
---
 guix/gnu-maintenance.scm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/guix/gnu-maintenance.scm b/guix/gnu-maintenance.scm
index 10a6ec05f1..4cd501e492 100644
--- a/guix/gnu-maintenance.scm
+++ b/guix/gnu-maintenance.scm
@@ -806,10 +806,16 @@ (define http-url?
 (define (latest-html-updatable-release package)
   "Return the latest release of PACKAGE.  Do that by crawling the HTML page of
 the directory containing its source tarball."
+  (define (http-url? url)
+    (match (string->uri url)
+      (#f #f)
+      (uri (let ((scheme (uri-scheme uri)))
+             (memq scheme '(http https))))))
   (let* ((uri       (string->uri
                      (match (origin-uri (package-source package))
                        ((? string? url) url)
-                       ((url _ ...) url))))
+                       ;; We need filter out possibly 'mirror://' urls.
+                       ((? list? urls) (first (filter http-url? urls))))))
          (custom    (assoc-ref (package-properties package)
                                'release-monitoring-url))
          (base      (or custom
-- 
2.37.3