From bd908af0c619cb1b74afeeb07839d7af08de9d91 Mon Sep 17 00:00:00 2001 From: Simon Tournier Date: Tue, 18 Jun 2024 16:02:51 +0200 Subject: swh: Specify 'extid_version' when looking up by external ID. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported in . * guix/swh.scm (swh-url): Don't add trailing slash when URL contains parameters. (lookup-external-id): Specify 'extid_version' to avoid SWH bug from previous erroneous nar hash computations with the initial SWH deployment of this feature. Change-Id: Iea2a5256e0612dae95567907bb11edb92a50df73 Co-authored-by: Ludovic Courtès --- guix/swh.scm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/guix/swh.scm b/guix/swh.scm index f602cd89d1..fd17b04b75 100644 --- a/guix/swh.scm +++ b/guix/swh.scm @@ -165,10 +165,16 @@ (define url (string-append root (string-join rest "/" 'prefix))) - ;; Ensure there's a trailing slash or we get a redirect. - (if (string-suffix? "/" url) - url - (string-append url "/"))) + (define (contains-parameters? url) + (match (string-rindex url #\/) + (#f #f) + (offset (string-index (string-drop url (+ 1 offset)) #\?)))) + + ;; Ensure there's a trailing slash or we get a redirect. Don't do that if + ;; URL contains parameters. + (cond ((string-suffix? "/" url) url) + ((contains-parameters? url) url) + (else (string-append url "/")))) ;; XXX: Work around a bug in Guile 3.0.2 where #:verify-certificate? would ;; be ignored (). @@ -460,8 +466,11 @@ FALSE-IF-404? is true, return #f upon 404 responses." "Return the external ID record for ID, a bytevector, of the given TYPE (currently one of: \"bzr-nodeid\", \"hg-nodeid\", \"nar-sha256\", \"checksum-sha512\")." + ;; Specify "extid_version=1" as explained in + ;; . (call (swh-url "/api/1/extid" type - (string-append "hex:" (bytevector->base16-string id))) + (string-append "hex:" (bytevector->base16-string id) + "/?extid_version=1")) json->external-id)) (define* (lookup-directory-by-nar-hash hash #:optional (algorithm 'sha256)) -- cgit v1.2.3