diff options
| -rwxr-xr-x | guix/scripts/substitute-binary.scm | 13 | ||||
| -rw-r--r-- | guix/utils.scm | 25 | ||||
| -rw-r--r-- | tests/utils.scm | 11 |
3 files changed, 37 insertions, 12 deletions
diff --git a/guix/scripts/substitute-binary.scm b/guix/scripts/substitute-binary.scm index 7ac12ddef2a..4e49b0c3ac7 100755 --- a/guix/scripts/substitute-binary.scm +++ b/guix/scripts/substitute-binary.scm | |||
| @@ -400,16 +400,6 @@ indefinitely." | |||
| 400 | (call-with-output-file expiry-file | 400 | (call-with-output-file expiry-file |
| 401 | (cute write (time-second now) <>)))) | 401 | (cute write (time-second now) <>)))) |
| 402 | 402 | ||
| 403 | (define (decompressed-port compression input) | ||
| 404 | "Return an input port where INPUT is decompressed according to COMPRESSION, | ||
| 405 | along with a list of PIDs to wait for." | ||
| 406 | (match compression | ||
| 407 | ("none" (values input '())) | ||
| 408 | ("bzip2" (filtered-port `(,%bzip2 "-dc") input)) | ||
| 409 | ("xz" (filtered-port `(,%xz "-dc") input)) | ||
| 410 | ("gzip" (filtered-port `(,%gzip "-dc") input)) | ||
| 411 | (else (error "unsupported compression scheme" compression)))) | ||
| 412 | |||
| 413 | (define (progress-report-port report-progress port) | 403 | (define (progress-report-port report-progress port) |
| 414 | "Return a port that calls REPORT-PROGRESS every time something is read from | 404 | "Return a port that calls REPORT-PROGRESS every time something is read from |
| 415 | PORT. REPORT-PROGRESS is a two-argument procedure such as that returned by | 405 | PORT. REPORT-PROGRESS is a two-argument procedure such as that returned by |
| @@ -598,7 +588,8 @@ substituter disabled~%") | |||
| 598 | (current-error-port)))) | 588 | (current-error-port)))) |
| 599 | (progress-report-port progress raw))) | 589 | (progress-report-port progress raw))) |
| 600 | ((input pids) | 590 | ((input pids) |
| 601 | (decompressed-port (narinfo-compression narinfo) | 591 | (decompressed-port (and=> (narinfo-compression narinfo) |
| 592 | string->symbol) | ||
| 602 | progress))) | 593 | progress))) |
| 603 | ;; Unpack the Nar at INPUT into DESTINATION. | 594 | ;; Unpack the Nar at INPUT into DESTINATION. |
| 604 | (restore-file input destination) | 595 | (restore-file input destination) |
diff --git a/guix/utils.scm b/guix/utils.scm index 15a43900748..f786c83f471 100644 --- a/guix/utils.scm +++ b/guix/utils.scm | |||
| @@ -70,7 +70,10 @@ | |||
| 70 | call-with-temporary-output-file | 70 | call-with-temporary-output-file |
| 71 | with-atomic-file-output | 71 | with-atomic-file-output |
| 72 | fold2 | 72 | fold2 |
| 73 | filtered-port)) | 73 | |
| 74 | filtered-port | ||
| 75 | compressed-port | ||
| 76 | decompressed-port)) | ||
| 74 | 77 | ||
| 75 | 78 | ||
| 76 | ;;; | 79 | ;;; |
| @@ -200,6 +203,26 @@ buffered data is lost." | |||
| 200 | (close-port out) | 203 | (close-port out) |
| 201 | (loop in (cons child pids))))))))) | 204 | (loop in (cons child pids))))))))) |
| 202 | 205 | ||
| 206 | (define (decompressed-port compression input) | ||
| 207 | "Return an input port where INPUT is decompressed according to COMPRESSION, | ||
| 208 | a symbol such as 'xz." | ||
| 209 | (match compression | ||
| 210 | ((or #f 'none) (values input '())) | ||
| 211 | ('bzip2 (filtered-port `(,%bzip2 "-dc") input)) | ||
| 212 | ('xz (filtered-port `(,%xz "-dc") input)) | ||
| 213 | ('gzip (filtered-port `(,%gzip "-dc") input)) | ||
| 214 | (else (error "unsupported compression scheme" compression)))) | ||
| 215 | |||
| 216 | (define (compressed-port compression input) | ||
| 217 | "Return an input port where INPUT is decompressed according to COMPRESSION, | ||
| 218 | a symbol such as 'xz." | ||
| 219 | (match compression | ||
| 220 | ((or #f 'none) (values input '())) | ||
| 221 | ('bzip2 (filtered-port `(,%bzip2 "-c") input)) | ||
| 222 | ('xz (filtered-port `(,%xz "-c") input)) | ||
| 223 | ('gzip (filtered-port `(,%gzip "-c") input)) | ||
| 224 | (else (error "unsupported compression scheme" compression)))) | ||
| 225 | |||
| 203 | 226 | ||
| 204 | ;;; | 227 | ;;; |
| 205 | ;;; Nixpkgs. | 228 | ;;; Nixpkgs. |
diff --git a/tests/utils.scm b/tests/utils.scm index 85daa3db919..39cad701b89 100644 --- a/tests/utils.scm +++ b/tests/utils.scm | |||
| @@ -150,6 +150,17 @@ | |||
| 150 | (any (compose (negate zero?) cdr waitpid) | 150 | (any (compose (negate zero?) cdr waitpid) |
| 151 | pids)))) | 151 | pids)))) |
| 152 | 152 | ||
| 153 | (test-assert "compressed-port, decompressed-port, non-file" | ||
| 154 | (let ((data (call-with-input-file (search-path %load-path "guix.scm") | ||
| 155 | get-bytevector-all))) | ||
| 156 | (let*-values (((compressed pids1) | ||
| 157 | (compressed-port 'xz (open-bytevector-input-port data))) | ||
| 158 | ((decompressed pids2) | ||
| 159 | (decompressed-port 'xz compressed))) | ||
| 160 | (and (every (compose zero? cdr waitpid) | ||
| 161 | (append pids1 pids2)) | ||
| 162 | (equal? (get-bytevector-all decompressed) data))))) | ||
| 163 | |||
| 153 | (false-if-exception (delete-file temp-file)) | 164 | (false-if-exception (delete-file temp-file)) |
| 154 | (test-equal "fcntl-flock wait" | 165 | (test-equal "fcntl-flock wait" |
| 155 | 42 ; the child's exit status | 166 | 42 ; the child's exit status |
