From patchwork Tue Aug 22 16:52:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 53107 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id DAD2B27BBEA; Tue, 22 Aug 2023 17:57:11 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D7A0727BBE2 for ; Tue, 22 Aug 2023 17:57:10 +0100 (BST) 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 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * 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".