From 946288288991899d857e34e5bfa3bcc514380073 Mon Sep 17 00:00:00 2001 From: Steve Sprang Date: Thu, 17 Sep 2015 04:22:01 -0700 Subject: 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): Use BASENAME as default for parameter 'abbreviation'. (url-fetch): Display extra newlines for readability. --- guix/build/download.scm | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'guix/build') diff --git a/guix/build/download.scm b/guix/build/download.scm index d362fc1f26..be4a5810af 100644 --- a/guix/build/download.scm +++ b/guix/build/download.scm @@ -101,15 +101,14 @@ (define* (progress-bar % #:optional (bar-width 20)) (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). If the string +does not overflow, the last char in RIGHT will be flush with the LEN +column." + (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 @@ -121,7 +120,7 @@ (define* (store-path-abbreviation store-path #:optional (prefix-length 6)) (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 @@ -519,7 +518,7 @@ (define uri (_ (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) -- cgit v1.2.3 From 75726135ce017f37ae57181e011ceea95c56dd3a Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 24 Sep 2015 21:54:37 +0200 Subject: download: Don't abbreviate things that are not store items. Fixes a regression introduced in a8be7b9a. * guix/build/download.scm (store-path-abbreviation): Return STORE-PATH if it's not an actual store path. Fixes an out-of-range exception when running tests/substitute.scm and tests/store.scm. --- guix/build/download.scm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'guix/build') diff --git a/guix/build/download.scm b/guix/build/download.scm index be4a5810af..4b7c53d2c6 100644 --- a/guix/build/download.scm +++ b/guix/build/download.scm @@ -111,12 +111,15 @@ (define (string-pad-middle left right len) (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 -characters of the hash." - (let ((base (basename store-path))) - (string-append (string-take base prefix-length) - "…" - (string-drop base 32)))) + "If STORE-PATH is the file name of a store entry, return an abbreviation of +STORE-PATH for display, showing PREFIX-LENGTH characters of the hash. +Otherwise return STORE-PATH." + (if (string-prefix? (%store-directory) store-path) + (let ((base (basename store-path))) + (string-append (string-take base prefix-length) + "…" + (string-drop base 32))) + store-path)) (define* (progress-proc file size #:optional (log-port (current-output-port)) -- cgit v1.2.3