unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Xinglu Chen <public@yoctocell.xyz>
To: 50874@debbugs.gnu.org
Subject: [bug#50874] [PATCH] lint: Check if HTTPS version of HTTP URL exists.
Date: Tue, 28 Sep 2021 21:09:10 +0200	[thread overview]
Message-ID: <e2047d5738d30969bc766ef85ea65715954a6927.1632855961.git.public@yoctocell.xyz> (raw)

* guix/lint.scm (check-if-https-uri-exists?): New procedure.
(check-home-page, check-source): Use it.
---
I don’t really know how to test this while making it future-proof, any
suggestions?

 guix/lint.scm | 41 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/guix/lint.scm b/guix/lint.scm
index 527fda165a..246a5ab9c8 100644
--- a/guix/lint.scm
+++ b/guix/lint.scm
@@ -875,17 +875,44 @@ (define (validate-uri uri package field)
       (else
        (error "internal linter error" status)))))
 
+(define (check-if-https-uri-exists? uri field package)
+  "Given a URI that uses HTTP, check whether a HTTPS version exists."
+  (guard (c ((http-get-error? c)
+             #f))
+    (catch #t
+      (lambda ()
+        (let* ((url (uri->string uri))
+               (https-url (string-append
+                           "https" (string-drop url (string-length "http"))))
+               (https-uri (string->uri https-url)))
+          (when (http-fetch/cached https-uri)
+            (make-warning package
+                          (G_ "HTTPS version is available for: ~a")
+                          (list url)
+                          #:field field))))
+      (match-lambda*
+        ((or ('gnutls-error _ ...) ('tls-certificate-error _ ...))
+         #f)
+        (args
+         (apply throw args))))))
+
 (define (check-home-page package)
   "Emit a warning if PACKAGE has an invalid 'home-page' field, or if that
 'home-page' is not reachable."
-  (let ((uri (and=> (package-home-page package) string->uri)))
+  (let* ((home-page (package-home-page package))
+         (uri (and=> home-page string->uri)))
     (cond
      ((uri? uri)
       (match (validate-uri uri package 'home-page)
         ((and (? lint-warning? warning) warning)
          (list warning))
-        (_ '())))
-     ((not (package-home-page package))
+        (_ (if (eq? (uri-scheme uri) 'http)
+               (match (check-if-https-uri-exists? uri 'home-page package)
+                 ((? lint-warning? warning)
+                  (list warning))
+                 (_ '()))
+               '()))))
+     ((not home-page)
       (if (or (string-contains (package-name package) "bootstrap")
               (string=? (package-name package) "ld-wrapper"))
           '()
@@ -1079,8 +1106,12 @@ (define (warnings-for-uris uris)
         ((uri rest ...)
          (match (validate-uri uri package 'source)
            (#t
-            ;; We found a working URL, so stop right away.
-            '())
+            (if (eq? (uri-scheme uri) 'http)
+               (match (check-if-https-uri-exists? uri 'source package)
+                 ((? lint-warning? warning)
+                  (list warning))
+                 (_ '()))
+               '()))
            (#f
             ;; Unsupported URL or other error, skip.
             (loop rest warnings))

base-commit: 009f0fc3dde0c2162c6df02fc4790a9f1d909e99
-- 
2.33.0







             reply	other threads:[~2021-09-28 19:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28 19:09 Xinglu Chen [this message]
2021-10-02 15:15 ` [bug#50874] [PATCH] lint: Check if HTTPS version of HTTP URL exists Ludovic Courtès
2021-10-09  9:57   ` Xinglu Chen
2021-10-09 10:11     ` Xinglu Chen
2021-10-10 13:12     ` Ludovic Courtès

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

  List information: https://guix.gnu.org/

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

  git send-email \
    --in-reply-to=e2047d5738d30969bc766ef85ea65715954a6927.1632855961.git.public@yoctocell.xyz \
    --to=public@yoctocell.xyz \
    --cc=50874@debbugs.gnu.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).