diff options
author | Ludovic Courtès <ludo@gnu.org> | 2018-07-19 17:12:48 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2018-07-19 17:12:48 +0200 |
commit | 83099892e0cf0d9c59f5e1a0774331026e48baa8 (patch) | |
tree | c65193896df03965028da939f75e72f46d4fd18b | |
parent | c71cd4a61fc8085ccb17169aad826d6f9ee1718b (diff) | |
download | guix-83099892e0cf0d9c59f5e1a0774331026e48baa8.tar guix-83099892e0cf0d9c59f5e1a0774331026e48baa8.tar.gz |
deduplication: Remove 'counting-wrapper-port'.
* guix/store/deduplication.scm (counting-wrapper-port): Remove.
(nar-sha256): Call 'port-position' directly on PORT.
-rw-r--r-- | guix/store/deduplication.scm | 34 |
1 files changed, 6 insertions, 28 deletions
diff --git a/guix/store/deduplication.scm b/guix/store/deduplication.scm index 6ff4a50de5..8234819f14 100644 --- a/guix/store/deduplication.scm +++ b/guix/store/deduplication.scm @@ -31,37 +31,15 @@ #:export (nar-sha256 deduplicate)) -;; Would it be better to just make WRITE-FILE give size as well? I question -;; the general utility of this approach. -(define (counting-wrapper-port output-port) - "Some custom ports don't implement GET-POSITION at all. But if we want to -figure out how many bytes are being written, we will want to use that. So this -makes a wrapper around a port which implements GET-POSITION." - (let ((byte-count 0)) - (make-custom-binary-output-port "counting-wrapper" - (lambda (bytes offset count) - (set! byte-count - (+ byte-count count)) - (put-bytevector output-port bytes - offset count) - count) - (lambda () - byte-count) - #f - (lambda () - (close-port output-port))))) - (define (nar-sha256 file) "Gives the sha256 hash of a file and the size of the file in nar form." (let-values (((port get-hash) (open-sha256-port))) - (let ((wrapper (counting-wrapper-port port))) - (write-file file wrapper) - (force-output wrapper) - (force-output port) - (let ((hash (get-hash)) - (size (port-position wrapper))) - (close-port wrapper) - (values hash size))))) + (write-file file port) + (force-output port) + (let ((hash (get-hash)) + (size (port-position port))) + (close-port port) + (values hash size)))) (define (tempname-in directory) "Gives an unused temporary name under DIRECTORY. Not guaranteed to still be |