From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id IPYHD+fo5GQztAAASxT56A (envelope-from ) for ; Tue, 22 Aug 2023 18:57:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id sNTfDufo5GTNpwAAauVa8A (envelope-from ) for ; Tue, 22 Aug 2023 18:57:11 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 033E23D6A1 for ; Tue, 22 Aug 2023 18:57:11 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=gRTUsP77; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1692723431; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=id3CChLigFwGUS/lHbcs8VAsJ/enUdGiNVlbtSUEaEM=; b=pOSIUQeoSItpv9oX4iFSIqKfc3nJTbGFtY6nD8/oYZqh1JOyEnqTslXwNSDjtAR59usLyn jrxZBZSYp86Qgq5Jl34J+Ub6DUMtVjMma3ZfGeQh8DJGFmo8rIxT9v+1xVZmef7VzBVIva /oaGQQIHrlQR2FyV4bXPvYFOYMW8r35iOhRlvNA0gWLx5EVee5Axy38QTFz7BOKZMWi2Xe RBqIemd7PRz02DWkefiV3DxaNA5rusI7Z2Kw/sIf/AXqsidvU126xj+hD4v2Tpr7MDbUKZ dfOJtLNDfGIBcSV8jIxdlX0x/ukJUewvsezsQdQ+lIdxSxxiatfppr6v4ItYqg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=gRTUsP77; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1692723431; a=rsa-sha256; cv=none; b=AJIl508qSz1I2V+8Rp+BIG/vWgV3uMMzkSk21HP1vxM0WWj75J6IPqTT1JXfgwVOa/QT39 ubJ0tL1obiJrgstdZRYLJmSygr7lmJXggJVVIFvLnhStu3Kb9AT2VpCaN4oo+SPF+LZE0K U0MN3EAh5K4NEqkONSqX/WHZUX2pYc8p/94s4AhRY5HmAgVyOKXU/cnrR8XTukjBjgsUY9 6SnFvGcqmLQ8wB76QWct7MhCaSwTcQa4TOuXb7zlakspYegUT2jPeFBQJkYwGgsD/fHJRc AFKlGJ94AeJ/ZYz/rwck03FZ7dg2Tdymp4CDjNdu3EmVcfV9DHin4nufhlJ8Bg== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYUfm-0004Zt-KP; Tue, 22 Aug 2023 12:56:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYUfg-0004Ux-7n for guix-patches@gnu.org; Tue, 22 Aug 2023 12:56:00 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYUff-0000uB-Uw; Tue, 22 Aug 2023 12:55:59 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qYUfi-0007jS-QZ; Tue, 22 Aug 2023 12:56:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65230] [PATCH v4 07/10] gnu-maintenance: Extract 'canonicalize-url' from 'import-html-release'. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 22 Aug 2023 16:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65230 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65230@debbugs.gnu.org Cc: Maxim Cournoyer , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 65230-submit@debbugs.gnu.org id=B65230.169272331129605 (code B ref 65230); Tue, 22 Aug 2023 16:56:02 +0000 Received: (at 65230) by debbugs.gnu.org; 22 Aug 2023 16:55:11 +0000 Received: from localhost ([127.0.0.1]:60344 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qYUet-0007hK-26 for submit@debbugs.gnu.org; Tue, 22 Aug 2023 12:55:11 -0400 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]:42373) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qYUep-0007fe-D0 for 65230@debbugs.gnu.org; Tue, 22 Aug 2023 12:55:07 -0400 Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-76d7fcb2c62so208804385a.1 for <65230@debbugs.gnu.org>; Tue, 22 Aug 2023 09:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692723299; x=1693328099; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=id3CChLigFwGUS/lHbcs8VAsJ/enUdGiNVlbtSUEaEM=; b=gRTUsP77Z2hkuGjZxCl6J9ce7CtiX8HHHK/Xr1LwhClylhmEp/iVEh+dRfjBBtrgGq BN2Apwthe4WJN/2b/Jxjp2x9upZj7QISWtGIl70o0MvKAuMlIfyhLiVGRqOdaBs8DSze hdeNUlnQM+Pze3MpitmI/hdZgxNh0R9CIr/2BPm/8mHWKpybEoX7p484Ef/nYU3AN37Y zWNkIXGBBXkV8JbdpoqKhFUhd/l8na8I6Gn2Of+ybfY6Z1ZHwhUSavI4oW2kxxWPn9oy I7H4P6GHqI74wA2sQdyo8u0vM0cj/fCnuDuvJMJEtrhYijH5LpHp9EfJbj24+B7CJ6IX wq9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692723299; x=1693328099; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=id3CChLigFwGUS/lHbcs8VAsJ/enUdGiNVlbtSUEaEM=; b=PR7xFvOji53ktzAbAwrXlc0sS+iXtSqjBQCWxqkIbAyn6PsoIHYXBDX+LVVIxUdP3i eWbg1yEkz3KqMSPIFyZaWsbaScU+GnE0sS3F82avnBJ9O97TdOPv/di2eeItQqYcujm1 crpdzLfPBCuQ86wqSP3UwWo1r1fbywh0nqPKWtPHQYIgEzGsb2mxWSZMwUcGEKyzJ+oS JM2h2pt7bXTE7ckHoCNlIVoRWRB7EEtdHhdL8cNV9T9/1umC1kmAb1Q4wrnoyDkOcuAa icc9Mb88CyaSuag16ZNZaHpGiWPsLYETpckFacwsh8ZhHUijWvakX4OQoX7CboVKD/Hb RGYg== X-Gm-Message-State: AOJu0Yy8Z/ceXTztHJn4gmk0sjcrUrCuEP4+TsFRMYVL/7NuNpBcfM1I sKEqaanTX+CZqmduGJmTYVVQMxkX1O4= X-Google-Smtp-Source: AGHT+IG0tXlXai9ieSwViDoq6s3NrPkssEcjAOtonN3zhXxOhz8wHzC2rdeS9wkOuHMDfhyivD0C0A== X-Received: by 2002:a05:620a:1aa3:b0:76d:a784:9685 with SMTP id bl35-20020a05620a1aa300b0076da7849685mr8271513qkb.28.1692723298658; Tue, 22 Aug 2023 09:54:58 -0700 (PDT) Received: from localhost.localdomain (dsl-158-129.b2b2c.ca. [66.158.158.129]) by smtp.gmail.com with ESMTPSA id p12-20020ae9f30c000000b007678973eaa1sm3336262qkg.127.2023.08.22.09.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 09:54:58 -0700 (PDT) From: Maxim Cournoyer Date: Tue, 22 Aug 2023 12:52:24 -0400 Message-ID: <54dea9a4e14ab5a2bb9fe29dab6c6b703c788b4a.1692723147.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <06b6c57b1af15b6ddca780182fc4a5e5264a67db.1692723147.git.maxim.cournoyer@gmail.com> References: <06b6c57b1af15b6ddca780182fc4a5e5264a67db.1692723147.git.maxim.cournoyer@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx2.migadu.com X-Migadu-Spam-Score: 4.80 X-Spam-Score: 4.80 X-Migadu-Queue-Id: 033E23D6A1 X-TUID: +yzVWz4q+yMV * guix/gnu-maintenance.scm (canonicalize-url): New procedure, extracted from... (import-html-release): ... here. Use it. Rename inner PACKAGE variable to NAME, to explicit it is a string and not a package object. --- (no changes since v1) guix/gnu-maintenance.scm | 70 +++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/guix/gnu-maintenance.scm b/guix/gnu-maintenance.scm index 6f08e2e295..9eff98217e 100644 --- a/guix/gnu-maintenance.scm +++ b/guix/gnu-maintenance.scm @@ -491,6 +491,33 @@ (define (url->links url) (close-port port) (delete-duplicates (html-links sxml)))) +(define (canonicalize-url url base-url) + "Make relative URL absolute, by appending URL to BASE-URL as required. If +URL is a directory instead of a file, it should be suffixed with a slash (/)." + (cond ((and=> (string->uri url) uri-scheme) + ;; Fully specified URL. + url) + ((string-prefix? "//" url) + ;; Full URL lacking a URI scheme. Reuse the URI scheme of the + ;; document that contains the URL. + (string-append (symbol->string (uri-scheme (string->uri base-url))) + ":" url)) + ((string-prefix? "/" url) + ;; Absolute URL. + (let ((uri (string->uri base-url))) + (uri->string + (build-uri (uri-scheme uri) + #:host (uri-host uri) + #:port (uri-port uri) + #:path url)))) + ;; URL is relative to BASE-URL, which is assumed to be a directory. + ((string-suffix? "/" base-url) + (string-append base-url url)) + (else + ;; URL is relative to BASE-URL, which is assumed to denote a file + ;; within a directory. + (string-append (dirname base-url) "/" url)))) + (define* (import-html-release base-url package #:key (version #f) @@ -508,11 +535,12 @@ (define* (import-html-release base-url package if any. Otherwise, FILE->SIGNATURE must be a procedure; it is passed a source file URL and must return the corresponding signature URL, or #f it signatures are unavailable." - (let* ((package (package-upstream-name package)) + (let* ((name (package-upstream-name package)) (url (if (string-null? directory) base-url (string-append base-url directory "/"))) - (links (url->links url))) + (links (map (cut canonicalize-url <> url) (url->links url)))) + (define (file->signature/guess url) "Return the first link that matches a signature extension, else #f." (let ((base (basename url))) @@ -526,42 +554,12 @@ (define* (import-html-release base-url package (define (url->release url) "Return an object if a release file was found at URL, -else #f." - (let* ((base (basename url)) - (base-url (string-append base-url directory)) - (url (cond ((and=> (string->uri url) uri-scheme) ;full URL? - url) - ;; full URL, except for URI scheme. Reuse the URI - ;; scheme of the document that contains the link. - ((string-prefix? "//" url) - (string-append - (symbol->string (uri-scheme (string->uri base-url))) - ":" url)) - ((string-prefix? "/" url) ;absolute path? - (let ((uri (string->uri base-url))) - (uri->string - (build-uri (uri-scheme uri) - #:host (uri-host uri) - #:port (uri-port uri) - #:path url)))) - - ;; URL is a relative path and BASE-URL may or may not - ;; end in slash. - ((string-suffix? "/" base-url) - (string-append base-url url)) - (else - ;; If DIRECTORY is non-empty, assume BASE-URL - ;; denotes a directory; otherwise, assume BASE-URL - ;; denotes a file within a directory, and that URL - ;; is relative to that directory. - (string-append (if (string-null? directory) - (dirname base-url) - base-url) - "/" url))))) - (and (release-file? package base) +else #f. URL is assumed to fully specified." + (let ((base (basename url))) + (and (release-file? name base) (let ((version (tarball->version base))) (upstream-source - (package package) + (package name) (version version) ;; uri-mirror-rewrite: Don't turn nice mirror:// URIs into ftp:// ;; URLs during "guix refresh -u". -- 2.41.0