diff mbox series

[bug#50289] import: go: Fix import when import path redirects.

Message ID c9ee1efc228bc7ba2287d464734e995502ef46a8.1630374913.git.iskarian@mgsn.dev
State Accepted
Headers show
Series [bug#50289] import: go: Fix import when import path redirects. | expand

Checks

Context Check Description
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Sarah Morgensen Aug. 31, 2021, 2:05 a.m. UTC
* guix/import/go.scm (fetch-module-meta-data): If no meta entries
have a matching import prefix, return the first entry instead of #f.
---
X-Debbugs-CC: Attila Lendvai <attila@lendvai.name>

Hello Guix,

As reported by Attila on IRC, the Go importer currently chokes when the
import path URL redirects, for example with "github.com/prometheus/tsdb".

This is due to my modification to 'fetch-module-meta-data' to handle multiple
package's meta tags on one page [0].  It selects the meta based on whether its
import prefix matches the URL we requested.  This breaks when the URL
redirects but the import path is not changed (I did not realize that this
was valid... go figure).  This patch fixes that by falling back to the first
meta if none match.

[0] https://issues.guix.gnu.org/49591

--
Sarah

 guix/import/go.scm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)


base-commit: 994d8ce394e88b55985241b7b14f6a8459bcf9e8

Comments

Ludovic Courtès Sept. 7, 2021, 1:55 p.m. UTC | #1
Hi,

Sarah Morgensen <iskarian@mgsn.dev> skribis:

> * guix/import/go.scm (fetch-module-meta-data): If no meta entries
> have a matching import prefix, return the first entry instead of #f.
> ---
> X-Debbugs-CC: Attila Lendvai <attila@lendvai.name>
>
> Hello Guix,
>
> As reported by Attila on IRC, the Go importer currently chokes when the
> import path URL redirects, for example with "github.com/prometheus/tsdb".
>
> This is due to my modification to 'fetch-module-meta-data' to handle multiple
> package's meta tags on one page [0].  It selects the meta based on whether its
> import prefix matches the URL we requested.  This breaks when the URL
> redirects but the import path is not changed (I did not realize that this
> was valid... go figure).  This patch fixes that by falling back to the first
> meta if none match.
>
> [0] https://issues.guix.gnu.org/49591

Applied, thank you!

Ludo’.
diff mbox series

Patch

diff --git a/guix/import/go.scm b/guix/import/go.scm
index 617a0d0e23..57a135b9a9 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -483,9 +483,12 @@  (define (fetch-module-meta-data module-path)
     (match (select (html->sxml meta-data #:strict? #t))
       (() #f)                           ;nothing selected
       ((('content content-text) ..1)
-       (find (lambda (meta)
-               (string-prefix? (module-meta-import-prefix meta) module-path))
-             (map go-import->module-meta content-text))))))
+       (or
+        (find (lambda (meta)
+                (string-prefix? (module-meta-import-prefix meta) module-path))
+              (map go-import->module-meta content-text))
+        ;; Fallback to the first meta if no import prefixes match.
+        (go-import->module-meta (first content-text)))))))
 
 (define (module-meta-data-repo-url meta-data goproxy)
   "Return the URL where the fetcher which will be used can download the