From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id qM/bEHqclWGcKAAAgWs5BA (envelope-from ) for ; Thu, 18 Nov 2021 01:21:14 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id cN2RDHqclWETKQAAB5/wlQ (envelope-from ) for ; Thu, 18 Nov 2021 00:21:14 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id F180D34E7A for ; Thu, 18 Nov 2021 01:21:13 +0100 (CET) Received: from localhost ([::1]:51120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnVAu-0003hi-MX for larch@yhetil.org; Wed, 17 Nov 2021 19:21:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnVAk-0003gg-6j for guix-patches@gnu.org; Wed, 17 Nov 2021 19:21:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:50830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mnVAj-00088Y-Ua for guix-patches@gnu.org; Wed, 17 Nov 2021 19:21:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mnVAj-00070T-R2 for guix-patches@gnu.org; Wed, 17 Nov 2021 19:21:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51307] [PATCH v2 1/3] scripts: hash: Support several files. Resent-From: zimoun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 18 Nov 2021 00:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51307 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51307@debbugs.gnu.org Cc: ludo@gnu.org, zimoun Received: via spool by 51307-submit@debbugs.gnu.org id=B51307.163719484726865 (code B ref 51307); Thu, 18 Nov 2021 00:21:01 +0000 Received: (at 51307) by debbugs.gnu.org; 18 Nov 2021 00:20:47 +0000 Received: from localhost ([127.0.0.1]:34137 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mnVAU-0006zA-Rs for submit@debbugs.gnu.org; Wed, 17 Nov 2021 19:20:47 -0500 Received: from mail-wm1-f44.google.com ([209.85.128.44]:43932) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mnVAS-0006yf-1q for 51307@debbugs.gnu.org; Wed, 17 Nov 2021 19:20:45 -0500 Received: by mail-wm1-f44.google.com with SMTP id 67-20020a1c1946000000b0030d4c90fa87so3433710wmz.2 for <51307@debbugs.gnu.org>; Wed, 17 Nov 2021 16:20:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AsdNvgj5R7rdm45aQhwuhx082GGMq4PMmw6rHAjB99k=; b=YDc5ZNT6ah/qU09SQKpRm/41HdBk7yUxQjgy/CKze0ZJWpYY7SCeYdh30SpkSHbm+2 zRIJWucwgC/cIuUN2Py+fBBxk/enPhJ3uvWKBs1UpTPpSU2wr2wNrk7tGd/wPF/WRBOJ mhX+jfDVdSEe0dSl6jYJCNoOr4WVKkrNjC6alVVMbv6IAobx2UbdsRBdZoceGBy3FbsW ScdypyJU5kbsvK7FN8oAkCNZSBAMCjlOmHuaTw7TwWY+XLIM0iRf40+wldFNXg6HXoEs RZH1W26Pf3hhQssH3rzpH9LK6JGt+9CwLktaCCK67OYedzfI7x4YuJaCjFG800xU+J92 rPjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AsdNvgj5R7rdm45aQhwuhx082GGMq4PMmw6rHAjB99k=; b=1ZejHykEV5Q4fRK3gZgupyMszC8q6nFNHGzsIj8JSLewDb4Ydb8AAm512+XfUO4UXH ddzBVttRZTJs+ZT1BsVQEcfOIS5tWbxcialpVCMZoh4unFHSJaIbZ8Z8inKHwteAVvz5 y1EfPmhOB1RiqixLVPxYtlXyCpllH5Hb/3xLWXFGae5WkDSDyDbwqk463l5nhVRX36Au dXTgAZq4MrFgUEuKNfTyTqcDr45rGTewTlk8Y2GjCPg1QmoVN+Wi9AcLK0LgVdoHzx3d U+iAptfWCft3WQ83piivR+uRUHONNsJk0fXoxc05B0pgmw92rbLh3m1GwDO4LNhLLkPp IgLA== X-Gm-Message-State: AOAM530dEdGPwhK2jmCYixEw/hGHoCHrfnpT2/wcsALydOq+RnYgSgCA m8cSBDJq5/uUtrhH3WsN4xlXA6I4ap0= X-Google-Smtp-Source: ABdhPJxyVzW/cGvqNK9Fs9CSmhEzi8p2kXCAH9j+4FKwbTn3qWUm5w22eOUkPhkqbxUizvL6Te4gOQ== X-Received: by 2002:a05:600c:2dc1:: with SMTP id e1mr4652486wmh.170.1637194838264; Wed, 17 Nov 2021 16:20:38 -0800 (PST) Received: from localhost.localdomain ([193.48.40.117]) by smtp.gmail.com with ESMTPSA id y7sm1255927wrw.55.2021.11.17.16.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 16:20:37 -0800 (PST) From: zimoun Date: Thu, 18 Nov 2021 01:20:21 +0100 Message-Id: <20211118002023.3323307-2-zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211118002023.3323307-1-zimon.toutoune@gmail.com> References: <20211118002023.3323307-1-zimon.toutoune@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1637194874; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=AsdNvgj5R7rdm45aQhwuhx082GGMq4PMmw6rHAjB99k=; b=Gp0rLrV7Rt0PNHql0Q7gTPb5A8wz+bLYPkWQutENqKFaDppV9VDfYH7E3z9gGRthD1sh+V StOxF9nb14JFGuIuIsDGrfrmL18XhOhltafyb7Eeo3IDLnXSkyZ3QaJHxgV7EfYa7wQnwK Gay9zq+AZUC9uuenCUtzB3LLbyxRQzYDTIFwvGOF1WugVAV2GTMLEmVQwoSpOpkq+drBRz DbyALJcdzc71jX//RD4a38a+sQ0WVWW6e/p2nHIFGmsAXaqdyBpLzoQQqT0XJBmL8UO+Uc dEE8fKSsTqjf9P7u06tcQhLVwHCPBkvfXN9781ouGsj8cxNRgpJG9HahgylP2w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637194874; a=rsa-sha256; cv=none; b=JM3VY4D16VrY5UPshCG7B//3QH8oToz3s6B7zwxWVaLrxUmI6RPIAQpxo3svxxxSiuDQVv T1MLeYB3a0uskvePabvz8Jq7rmJZWmLCxtsxnIk+QwmUuQauDAP/QO1q7MdAps7w1Slt12 NiYkmguZEt3uljJoqGhnLYNwkXxTI0uRAgjIv9Qe/8ndq90U6JRReSfp8g4r6osp6roImM 3ePeiHODFPdwZxbIzmWiQBSgShs//8OFRNa6+/1nZM+QuXsooRttqmpvpiIbpPLtTXFmNp Xs1mv31E/of49reqV6p4XgZj/RU6hdCxeRLTLNzsDJUjymNu9GixWq+sl+pXdg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=YDc5ZNT6; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.86 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=YDc5ZNT6; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: F180D34E7A X-Spam-Score: -1.86 X-Migadu-Scanner: scn0.migadu.com X-TUID: 6e8NU2qYUB/Q * guix/scripts/hash.scm (guix-hash): Allow several files. [file-hash]: Catch system-error. [formatted-hash]: New procedure. --- guix/scripts/hash.scm | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index b8622373cc..12f542929b 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2013 Nikita Karetnikov ;;; Copyright © 2016 Jan Nieuwenhuizen ;;; Copyright © 2018 Tim Gesthuizen +;;; Copyright © 2021 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -149,27 +150,31 @@ (define (vcs-file? file stat) (define (file-hash file) ;; Compute the hash of FILE. ;; Catch and gracefully report possible '&nar-error' conditions. - (with-error-handling - (if (assoc-ref opts 'recursive?) + (if (assoc-ref opts 'recursive?) + (with-error-handling (let-values (((port get-hash) (open-hash-port (assoc-ref opts 'hash-algorithm)))) (write-file file port #:select? select?) (force-output port) - (get-hash)) - (match file - ("-" (port-hash (assoc-ref opts 'hash-algorithm) - (current-input-port))) - (_ (call-with-input-file file - (cute port-hash (assoc-ref opts 'hash-algorithm) - <>))))))) + (get-hash))) + (catch 'system-error + (lambda _ + (call-with-input-file file + (cute port-hash (assoc-ref opts 'hash-algorithm) + <>))) + (lambda args + (leave (G_ "~a ~a~%") + file + (strerror (system-error-errno args))))))) - (match args - ((file) - (catch 'system-error - (lambda () - (format #t "~a~%" (fmt (file-hash file)))) - (lambda args - (leave (G_ "~a~%") - (strerror (system-error-errno args)))))) - (x - (leave (G_ "wrong number of arguments~%")))))) + (define (formatted-hash thing) + (match thing + ("-" (with-error-handling + (fmt (port-hash (assoc-ref opts 'hash-algorithm) + (current-input-port))))) + (_ + (fmt (file-hash thing))))) + + (for-each + (compose (cute format #t "~a~%" <>) formatted-hash) + args))) -- 2.33.1