diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2018-07-20 13:49:50 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2018-07-20 15:01:33 +0200 |
| commit | 4f89a8eec69491b925f084381ea4de37527c9310 (patch) | |
| tree | 6d4051386b58ce4b7f699b20173fe0255a51a7a5 | |
| parent | a2662bfe9ccedc9d791696424988dcadff9247b0 (diff) | |
deduplication: Work around Guile bug in 'seek'.
Fixes <https://bugs.gnu.org/32161>.
Reported by Ricardo Wurmus <rekado@elephly.net>.
This mostly reverts 83099892e0cf0d9c59f5e1a0774331026e48baa8.
* guix/store/deduplication.scm (counting-wrapper-port): New procedure.
(nar-sha256): Use it.
| -rw-r--r-- | guix/store/deduplication.scm | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/guix/store/deduplication.scm b/guix/store/deduplication.scm index 8234819f142..8c19d7309e1 100644 --- a/guix/store/deduplication.scm +++ b/guix/store/deduplication.scm | |||
| @@ -31,14 +31,38 @@ | |||
| 31 | #:export (nar-sha256 | 31 | #:export (nar-sha256 |
| 32 | deduplicate)) | 32 | deduplicate)) |
| 33 | 33 | ||
| 34 | ;; XXX: This port is used as a workaround on Guile <= 2.2.4 where | ||
| 35 | ;; 'port-position' throws to 'out-of-range' when the offset is great than or | ||
| 36 | ;; equal to 2^32: <https://bugs.gnu.org/32161>. | ||
| 37 | (define (counting-wrapper-port output-port) | ||
| 38 | "Return two values: an output port that wraps OUTPUT-PORT, and a thunk to | ||
| 39 | retrieve the number of bytes written to OUTPUT-PORT." | ||
| 40 | (let ((byte-count 0)) | ||
| 41 | (values (make-custom-binary-output-port "counting-wrapper" | ||
| 42 | (lambda (bytes offset count) | ||
| 43 | (put-bytevector output-port bytes | ||
| 44 | offset count) | ||
| 45 | (set! byte-count | ||
| 46 | (+ byte-count count)) | ||
| 47 | count) | ||
| 48 | (lambda () | ||
| 49 | byte-count) | ||
| 50 | #f | ||
| 51 | (lambda () | ||
| 52 | (close-port output-port))) | ||
| 53 | (lambda () | ||
| 54 | byte-count)))) | ||
| 55 | |||
| 34 | (define (nar-sha256 file) | 56 | (define (nar-sha256 file) |
| 35 | "Gives the sha256 hash of a file and the size of the file in nar form." | 57 | "Gives the sha256 hash of a file and the size of the file in nar form." |
| 36 | (let-values (((port get-hash) (open-sha256-port))) | 58 | (let*-values (((port get-hash) (open-sha256-port)) |
| 37 | (write-file file port) | 59 | ((wrapper get-size) (counting-wrapper-port port))) |
| 60 | (write-file file wrapper) | ||
| 61 | (force-output wrapper) | ||
| 38 | (force-output port) | 62 | (force-output port) |
| 39 | (let ((hash (get-hash)) | 63 | (let ((hash (get-hash)) |
| 40 | (size (port-position port))) | 64 | (size (get-size))) |
| 41 | (close-port port) | 65 | (close-port wrapper) |
| 42 | (values hash size)))) | 66 | (values hash size)))) |
| 43 | 67 | ||
| 44 | (define (tempname-in directory) | 68 | (define (tempname-in directory) |
