GNU bug report logs -
#51307
[PATCH 0/2] guix hash: eases conversion
Previous Next
Reported by: zimoun <zimon.toutoune <at> gmail.com>
Date: Wed, 20 Oct 2021 16:51:01 UTC
Severity: normal
Tags: patch
Done: zimoun <zimon.toutoune <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
* 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 <nikita <at> karetnikov.org>
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke <at> gnu.org>
;;; Copyright © 2018 Tim Gesthuizen <tim.gesthuizen <at> yahoo.de>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
;;;
;;; 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
This bug report was last modified 3 years and 155 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.