From 11440f61cebd49d31d165f6433ec6e4b1afe728f Mon Sep 17 00:00:00 2001 From: Steve Sprang Date: Thu, 17 Sep 2015 04:22:01 -0700 Subject: [PATCH] download: Fix some minor progress-logging regressions. * guix/build/download.scm (string-pad-middle): Allow resulting padded string to overflow. (store-url-abbreviation): Remove unnecessary procedure. (progress-proc): Default abbreviation should be basename. (url-fetch): Insert some newlines for readability. --- guix/build/download.scm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/guix/build/download.scm b/guix/build/download.scm index 9b72e8f..e6de4d2 100644 --- a/guix/build/download.scm +++ b/guix/build/download.scm @@ -100,15 +100,13 @@ width of the bar is BAR-WIDTH." (define (string-pad-middle left right len) "Combine LEFT and RIGHT with enough padding in the middle so that the -resulting string has length at least LEN. This right justifies RIGHT." - (string-append left - (string-pad right (max 0 (- len (string-length left)))))) - -(define (store-url-abbreviation url) - "Return a friendlier version of URL for display." - (let ((store-path (string-append (%store-directory) "/" (basename url)))) - ;; Take advantage of the implementation for store paths. - (store-path-abbreviation store-path))) +resulting string has length at least LEN (it may overflow). This right +justifies RIGHT." + (let* ((total-used (+ (string-length left) + (string-length right))) + (num-spaces (max 1 (- len total-used))) + (padding (make-string num-spaces #\space))) + (string-append left padding right))) (define* (store-path-abbreviation store-path #:optional (prefix-length 6)) "Return an abbreviation of STORE-PATH for display, showing PREFIX-LENGTH @@ -120,7 +118,7 @@ characters of the hash." (define* (progress-proc file size #:optional (log-port (current-output-port)) - #:key (abbreviation identity)) + #:key (abbreviation basename)) "Return a procedure to show the progress of FILE's download, which is SIZE bytes long. The returned procedure is suitable for use as an argument to `dump-port'. The progress report is written to LOG-PORT, with ABBREVIATION @@ -518,7 +516,7 @@ on success." (_ (list (string->uri url)))))) (define (fetch uri file) - (format #t "starting download of `~a' from `~a'...~%" + (format #t "~%Starting download of ~a~%From ~a...~%" file (uri->string uri)) (case (uri-scheme uri) ((http https) -- 2.5.0