From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikita Karetnikov Subject: Re: [PATCH] Add 'guix hash'. Date: Wed, 10 Apr 2013 15:48:49 +0400 Message-ID: <8738uy7gim.fsf@karetnikov.org> References: <87li92alhe.fsf@karetnikov.org> <874nforp12.fsf@gnu.org> <8762015b0w.fsf@karetnikov.org> <871uap5ak8.fsf@karetnikov.org> <87zjxdvtqp.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:52631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPtTl-0002vB-3T for bug-guix@gnu.org; Wed, 10 Apr 2013 07:46:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPtTh-0004ZZ-Vf for bug-guix@gnu.org; Wed, 10 Apr 2013 07:46:17 -0400 In-Reply-To: <87zjxdvtqp.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Fri, 05 Apr 2013 18:15:42 +0200") 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: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: bug-guix@gnu.org --=-=-= > Ah, TOCTTOU, right. > You could do: > (let ((hash (catch 'system-error > (lambda () > (call-with-input-file ...)) > (lambda args > (leave (_ "error ..." (strerror (system-error-errno args)))))))) > ...) 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"))))) I guess that "wrong number of arguments" can be handled by (lambda args ...). Still, the above feels much safer. What do you think? --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBAgAGBQJRZVGmAAoJEM+IQzI9IQ385ooP/28bkz28EzHSgNl9p32o09AE TkGF1wgxsrcBE2EQkYRCyXsLxCCHtpWifxmsDeCBbRYD30TAcfQH082bohc7oE25 N4Zi58bTYGSmx8Iiad7a+CNf9AccQSLexNEDiJWZF5DtqiTlacoMwloOhbd7fJvJ Oe4+CYgEZKrnWCNrbTjSy1Zyh9jFcRKcyI0AW8MpJ59EyNh02zuD9g/cTm2HRj7b tBUjtBXqH/RTVwpaayz93MKWd5UTphW6a9D/Aq0p3H85m+ny056onhQxucAFCcYE /X7Nysj24Jcq+T+TgJIGVMRjaj1TlENR/bLsd2IlB2SfJ24IU18kTgEludiY0kgG AlVbH1975XVN5QVblqZQAQMGlgIjjjHrGuy+9j+Q0r68NPrlR2TAflQi5yNUgIYY kMMSWv44GLgsRlfO+94OZuio8DKT+Ni7zMPomRWIsSXpRgP+QHQkfIzMBQB+byzY cfaUWJFSvkqo3S+gg51nj+wZfDWygeEjCcJz6Uy6EXPzXKSYVIiqz0NwppeLrVjL dBcV2rNpHMM1EKTWrs0mdrJy+mV2j201tFT42JJIbX1EZvUfZzHkJMV+YCjjgOsN ZS4Yde9BDhuh8kTs4hgGfhczcOTKnHcmJQ1zXXk16i2NHf9ElhWzhDjpeWwXIqPb iTv2/0NbHlpjhaHRDyn4 =/A/e -----END PGP SIGNATURE----- --=-=-=--