diff mbox series

[bug#39753] guix: swh: Handle absolute URLs being returned by the API.

Message ID 20200223112033.16166-1-kuba@kadziolka.net
State Accepted
Headers show
Series [bug#39753] guix: swh: Handle absolute URLs being returned by the API. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job

Commit Message

Maja Kądziołka Feb. 23, 2020, 11:20 a.m. UTC
* guix/swh.scm (swh-url): Don't prepend (%swh-base-url) if a domain is
  already present.

This fixes the "guix lint: warning: while connecting to Software Heritage:
host lookup failure: Name or service not known" error message.
---
 guix/swh.scm | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/guix/swh.scm b/guix/swh.scm
index 8bdf9965f6..a948a8f28f 100644
--- a/guix/swh.scm
+++ b/guix/swh.scm
@@ -126,9 +126,16 @@ 
   (make-parameter "https://archive.softwareheritage.org"))
 
 (define (swh-url path . rest)
+  ;; URLs returned by the API may be relative or absolute. This has changed
+  ;; without notice before. Handle both cases by detecting whether the path
+  ;; starts with a domain.
+  (define root
+    (if (string-prefix? "/" path)
+      (string-append (%swh-base-url) path)
+      path))
+
   (define url
-    (string-append (%swh-base-url) path
-                   (string-join rest "/" 'prefix)))
+    (string-append root (string-join rest "/" 'prefix)))
 
   ;; Ensure there's a trailing slash or we get a redirect.
   (if (string-suffix? "/" url)