bug-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add 'guix hash'.


From: Ludovic Courtès
Subject: Re: [PATCH] Add 'guix hash'.
Date: Wed, 10 Apr 2013 13:54:30 +0200
User-agent: Gnus/5.130005 (Ma Gnus v0.5) Emacs/24.3 (gnu/linux)

Nikita Karetnikov <address@hidden> 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 
>> 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")))))

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’.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]