From patchwork Fri Sep 23 06:19:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 42873 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 4A41627BBEA; Fri, 23 Sep 2022 07:44:04 +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=0.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_PASS, URIBL_BLOCKED autolearn=no 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 B76FC27BBE9 for ; Fri, 23 Sep 2022 07:44:03 +0100 (BST) Received: from localhost ([::1]:45844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obcPq-00059x-ID for patchwork@mira.cbaines.net; Fri, 23 Sep 2022 02:44:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obc3b-00023x-3d for guix-patches@gnu.org; Fri, 23 Sep 2022 02:21:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40086) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1obc3a-00081j-Q4 for guix-patches@gnu.org; Fri, 23 Sep 2022 02:21:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1obc3a-0007JC-KU for guix-patches@gnu.org; Fri, 23 Sep 2022 02:21:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58017] [PATCH 1/2] substitute: Split nar download. References: <20220923061616.5453-1-ludo@gnu.org> In-Reply-To: <20220923061616.5453-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 23 Sep 2022 06:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58017 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58017@debbugs.gnu.org Cc: Attila Lendvai , 57978@debbugs.gnu.org, Ludovic =?utf-8?q?Court=C3=A8s?= , zimoun Received: via spool by 58017-submit@debbugs.gnu.org id=B58017.166391402627972 (code B ref 58017); Fri, 23 Sep 2022 06:21:02 +0000 Received: (at 58017) by debbugs.gnu.org; 23 Sep 2022 06:20:26 +0000 Received: from localhost ([127.0.0.1]:39154 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1obc2z-0007H2-Q3 for submit@debbugs.gnu.org; Fri, 23 Sep 2022 02:20:26 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49968) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1obc2y-0007Gi-64; Fri, 23 Sep 2022 02:20:24 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:49284) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obc2q-0007uy-5K; Fri, 23 Sep 2022 02:20:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=v8zk/MAZ5CmI+AWHnZJ9I77Ii2NvFYgBrf8bJ9F0cik=; b=q4Ut3ZolX4f1wa VAy+0BKigkFKNSD8nkjTppza1q7UGU8m2FymhjgmBq7lLwWLjjxnOsVCQ0gGKurNLiasaVaP8SLo7 eiIdoCf7F4fs5MrgfPnHobpNo1NJZUMQpw+Yn+cNXSA4GB3m7b24pyNVU3VkCdRV34MBUUXqkGqKe 6D5bxoqqVkfsguyuitdjTACqnXUUrqIHk+AwtHdJD/CUpl24PSzyEtmR6FtMcpjBRaSTOFDazX8kM ZRnDukiED9/IOZFfNF0c86gvWD2+kcNwzDd6sPY1J8bdF4QImMcGHIr0kJcvx4l2IWlwCxjb6/2/P 3J6xWL5ddlxYxs2DBOjQ==; Received: from [89.207.171.75] (port=38064 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1obc2o-0007Hi-Uw; Fri, 23 Sep 2022 02:20:15 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Fri, 23 Sep 2022 08:19:56 +0200 Message-Id: <20220923061957.5658-1-ludo@gnu.org> X-Mailer: git-send-email 2.37.3 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" X-getmail-retrieved-from-mailbox: Patches * guix/scripts/substitute.scm (download-nar): New procedure, with most of the code moved from... (process-substitution): ... here. Call it. --- guix/scripts/substitute.scm | 52 +++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm index cdf591ac4d..e3b382d0d8 100755 --- a/guix/scripts/substitute.scm +++ b/guix/scripts/substitute.scm @@ -437,20 +437,13 @@ (define-syntax-rule (with-cached-connection uri port exp ...) "Bind PORT with EXP... to a socket connected to URI." (call-with-cached-connection uri (lambda (port) exp ...))) -(define* (process-substitution port store-item destination - #:key cache-urls acl - deduplicate? print-build-trace?) - "Substitute STORE-ITEM (a store file name) from CACHE-URLS, and write it to -DESTINATION as a nar file. Verify the substitute against ACL, and verify its -hash against what appears in the narinfo. When DEDUPLICATE? is true, and if -DESTINATION is in the store, deduplicate its files. Print a status line to -PORT." - (define narinfo - (lookup-narinfo cache-urls store-item - (if (%allow-unauthenticated-substitutes?) - (const #t) - (cut valid-narinfo? <> acl)))) - +(define* (download-nar narinfo destination + #:key status-port + deduplicate? print-build-trace?) + "Download the nar prescribed in NARINFO, which is assumed to be authentic +and authorized, and write it to DESTINATION. When DEDUPLICATE? is true, and +if DESTINATION is in the store, deduplicate its files. Print a status line to +STATUS-PORT." (define destination-in-store? (string-prefix? (string-append (%store-prefix) "/") destination)) @@ -490,10 +483,6 @@ (define (fetch uri) (leave (G_ "unsupported substitute URI scheme: ~a~%") (uri->string uri))))) - (unless narinfo - (leave (G_ "no valid substitute for '~a'~%") - store-item)) - (let ((uri compression file-size (narinfo-best-uri narinfo #:fast-decompression? @@ -575,14 +564,37 @@ (define cpu-usage (let ((actual (get-hash))) (if (bytevector=? actual expected) ;; Tell the daemon that we're done. - (format port "success ~a ~a~%" + (format status-port "success ~a ~a~%" (narinfo-hash narinfo) (narinfo-size narinfo)) ;; The actual data has a different hash than that in NARINFO. - (format port "hash-mismatch ~a ~a ~a~%" + (format status-port "hash-mismatch ~a ~a ~a~%" (hash-algorithm-name algorithm) (bytevector->nix-base32-string expected) (bytevector->nix-base32-string actual))))))) +(define* (process-substitution port store-item destination + #:key cache-urls acl + deduplicate? print-build-trace?) + "Substitute STORE-ITEM (a store file name) from CACHE-URLS, and write it to +DESTINATION as a nar file. Verify the substitute against ACL, and verify its +hash against what appears in the narinfo. When DEDUPLICATE? is true, and if +DESTINATION is in the store, deduplicate its files. Print a status line to +PORT." + (define narinfo + (lookup-narinfo cache-urls store-item + (if (%allow-unauthenticated-substitutes?) + (const #t) + (cut valid-narinfo? <> acl)))) + + (unless narinfo + (leave (G_ "no valid substitute for '~a'~%") + store-item)) + + (download-nar narinfo destination + #:status-port port + #:deduplicate? deduplicate? + #:print-build-trace? print-build-trace?)) + ;;; ;;; Entry point.