summaryrefslogtreecommitdiff
path: root/guix/utils.scm
diff options
context:
space:
mode:
author宋文武 <iyzsong@member.fsf.org>2017-09-16 14:10:18 -0600
committer宋文武 <iyzsong@member.fsf.org>2017-09-20 19:49:31 +0800
commit798648515b77507c242752457b4dc17c155bad6e (patch)
treebc2eef3747fd694efd5c0c065e56330c8257f453 /guix/utils.scm
parentf1b65d0dd964e4c457e660b9289a357447939d93 (diff)
downloadgnu-guix-798648515b77507c242752457b4dc17c155bad6e.tar
gnu-guix-798648515b77507c242752457b4dc17c155bad6e.tar.gz
download: Don't report the progress too fast.
* guix/utils.scm (<progress-reporter>): New record type. (call-with-progress-reporter): New procedure. * guix/build/download.scm (dump-port*, rate-limited, progress-reporter/file): New procedures. (ftp-fetch, http-fetch): Use 'dump-port*'. (progress-proc): Remove procedure. * guix/scripts/substitute.scm (progress-report-port): Rewrite in terms of <progress-reporter>. (process-substitution): Adjust accordingly.
Diffstat (limited to 'guix/utils.scm')
-rw-r--r--guix/utils.scm32
1 files changed, 31 insertions, 1 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index 8fbbdc3563..de4aa65319 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -33,6 +33,7 @@
#:autoload (rnrs io ports) (make-custom-binary-input-port)
#:use-module ((rnrs bytevectors) #:select (bytevector-u8-set!))
#:use-module (guix memoization)
+ #:use-module (guix records)
#:use-module ((guix build utils) #:select (dump-port mkdir-p))
#:use-module ((guix build syscalls) #:select (mkdtemp! fdatasync))
#:use-module (ice-9 format)
@@ -94,7 +95,13 @@
call-with-decompressed-port
compressed-output-port
call-with-compressed-output-port
- canonical-newline-port))
+ canonical-newline-port
+
+ <progress-reporter>
+ progress-reporter
+ make-progress-reporter
+ progress-reporter?
+ call-with-progress-reporter))
;;;
@@ -747,3 +754,26 @@ a location object."
`((line . ,(and=> (location-line loc) 1-))
(column . ,(location-column loc))
(filename . ,(location-file loc))))
+
+
+;;;
+;;; Progress reporter.
+;;;
+
+(define-record-type* <progress-reporter>
+ progress-reporter make-progress-reporter progress-reporter?
+ (start progress-reporter-start) ; thunk
+ (report progress-reporter-report) ; procedure
+ (stop progress-reporter-stop)) ; thunk
+
+(define (call-with-progress-reporter reporter proc)
+ "Start REPORTER for progress reporting, and call @code{(@var{proc} report)}
+with the resulting report procedure. When @var{proc} returns, the REPORTER is
+stopped."
+ (match reporter
+ (($ <progress-reporter> start report stop)
+ (dynamic-wind start (lambda () (proc report)) stop))))
+
+;;; Local Variables:
+;;; eval: (put 'call-with-progress-reporter 'scheme-indent-function 1)
+;;; End: