From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH] Add 'guix hash'. Date: Wed, 10 Apr 2013 13:54:30 +0200 Message-ID: <87k3oa1tzd.fsf@gnu.org> References: <87li92alhe.fsf@karetnikov.org> <874nforp12.fsf@gnu.org> <8762015b0w.fsf@karetnikov.org> <871uap5ak8.fsf@karetnikov.org> <87zjxdvtqp.fsf@gnu.org> <8738uy7gim.fsf@karetnikov.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:56077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPtby-0005ob-AS for bug-guix@gnu.org; Wed, 10 Apr 2013 07:54:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPtbt-0007L7-KX for bug-guix@gnu.org; Wed, 10 Apr 2013 07:54:46 -0400 Received: from [2a01:e0b:1:123:ca0a:a9ff:fe03:271e] (port=51400 helo=xanadu.aquilenet.fr) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPtbt-0007JG-EB for bug-guix@gnu.org; Wed, 10 Apr 2013 07:54:41 -0400 In-Reply-To: <8738uy7gim.fsf@karetnikov.org> (Nikita Karetnikov's message of "Wed, 10 Apr 2013 15:48:49 +0400") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org To: Nikita Karetnikov Cc: bug-guix@gnu.org Nikita Karetnikov skribis: >> Ah, TOCTTOU, right. > >> You could do: > >> (let ((hash (catch 'system-error >> (lambda () >> (call-with-input-file ...)) >> (lambda args >> (leave (_ "error ..." (strerror (system-error-errno ar= gs)))))))) >> ...) > > Here is what I did (I'll remove "guix hash" when we have "warning"): > > (match args > ((file) > (catch 'system-error > (lambda () > (format #t "~a~%" > (call-with-input-file file > (compose fmt sha256 get-bytevector-all)))) > (lambda args > (leave (_ "~a: ~a~%") > "guix hash" (strerror (system-error-errno args)))))) > (_ > (leave (_ "~a: wrong number of arguments~%") > "guix hash"))))) Looks good. > I guess that "wrong number of arguments" can be handled by > (lambda args ...). Still, the above feels much safer. Not sure what you mean, but the above snippet is OK. Ludo=E2=80=99.