summaryrefslogtreecommitdiff
path: root/guix/progress.scm
diff options
context:
space:
mode:
authorMathieu Othacehe <m.othacehe@gmail.com>2019-12-31 11:04:51 +0100
committerMathieu Othacehe <m.othacehe@gmail.com>2019-12-31 11:04:51 +0100
commitce9383c090fff90acb3a555d0ccfe12d791fef17 (patch)
tree7b9cce156799486b94e4f3e55b03831638e73465 /guix/progress.scm
parent91be09de61c277d0f1b26cefcefcd0a7fae2e00d (diff)
parentfc4eb87dc45b169e3912c73bbf60cb8ce76b7c7c (diff)
downloadguix-patches-ce9383c090fff90acb3a555d0ccfe12d791fef17.tar
guix-patches-ce9383c090fff90acb3a555d0ccfe12d791fef17.tar.gz
Merge remote-tracking branch 'master' into core-updates.
Diffstat (limited to 'guix/progress.scm')
-rw-r--r--guix/progress.scm31
1 files changed, 31 insertions, 0 deletions
diff --git a/guix/progress.scm b/guix/progress.scm
index 349637dbcf..c7567a35fd 100644
--- a/guix/progress.scm
+++ b/guix/progress.scm
@@ -40,6 +40,7 @@
progress-reporter/file
progress-reporter/bar
progress-reporter/trace
+ progress-report-port
display-download-progress
erase-current-line
@@ -342,3 +343,33 @@ should be a <progress-reporter> object."
(put-bytevector out buffer 0 bytes)
(report total)
(loop total (get-bytevector-n! in buffer 0 buffer-size))))))))
+
+(define (progress-report-port reporter port)
+ "Return a port that continuously reports the bytes read from PORT using
+REPORTER, which should be a <progress-reporter> object."
+ (match reporter
+ (($ <progress-reporter> start report stop)
+ (let* ((total 0)
+ (read! (lambda (bv start count)
+ (let ((n (match (get-bytevector-n! port bv start count)
+ ((? eof-object?) 0)
+ (x x))))
+ (set! total (+ total n))
+ (report total)
+ n))))
+ (start)
+ (make-custom-binary-input-port "progress-port-proc"
+ read! #f #f
+ (lambda ()
+ ;; XXX: Kludge! When used through
+ ;; 'decompressed-port', this port ends
+ ;; up being closed twice: once in a
+ ;; child process early on, and at the
+ ;; end in the parent process. Ignore
+ ;; the early close so we don't output
+ ;; a spurious "download-succeeded"
+ ;; trace.
+ (unless (zero? total)
+ (stop))
+ (close-port port)))))))
+