diff options
author | Ludovic Courtès <ludo@gnu.org> | 2015-08-19 11:33:51 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2015-08-19 11:39:18 +0200 |
commit | 83bde59fb3db5827002a0049a5571e4163af5ff1 (patch) | |
tree | 627683584696b3ec7017325a8e3a4bf3c28417ab | |
parent | 40a7d4e58ba05f39bf11edab68de6d3ae9c43306 (diff) | |
download | guix-83bde59fb3db5827002a0049a5571e4163af5ff1.tar guix-83bde59fb3db5827002a0049a5571e4163af5ff1.tar.gz |
size: Get the item's size from the daemon rather than compute it.
This removes all I/O, which obviously makes things faster.
* guix/scripts/size.scm (file-size, store-item-exists?): Remove.
(query-path-info*): New procedure.
(file-size*): Rename to...
(file-size): ... this; adjust caller. Use 'query-path-info*' instead of
'file-size'.
-rw-r--r-- | guix/scripts/size.scm | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/guix/scripts/size.scm b/guix/scripts/size.scm index 92625d8a90..ee070f14b1 100644 --- a/guix/scripts/size.scm +++ b/guix/scripts/size.scm @@ -29,7 +29,6 @@ #:use-module (srfi srfi-11) #:use-module (srfi srfi-34) #:use-module (srfi srfi-37) - #:use-module (ice-9 ftw) #:use-module (ice-9 match) #:use-module (ice-9 format) #:export (profile? @@ -48,42 +47,24 @@ (self-size profile-self-size) ;size in bytes (closure-size profile-closure-size)) ;size of dependencies in bytes -(define (file-size file) - "Return the size of bytes of FILE, entering it if FILE is a directory." - (file-system-fold (const #t) - (lambda (file stat result) ;leaf - (+ (stat:size stat) result)) - (lambda (directory stat result) ;down - (+ (stat:size stat) result)) - (lambda (directory stat result) ;up - result) - (lambda (file stat result) ;skip - result) - (lambda (file stat errno result) - (format (current-error-port) - "file-size: ~a: ~a~%" file - (strerror errno)) - result) - 0 - file - lstat)) - (define substitutable-path-info* (store-lift substitutable-path-info)) -(define (store-item-exists? item) - "Return #t if ITEM is in the store, and protect it from GC. Otherwise -return #f." +(define (query-path-info* item) + "Monadic version of 'query-path-info' that returns #f when ITEM is not in +the store." (lambda (store) - (add-temp-root store item) - (values (valid-path? store item) store))) + (guard (c ((nix-protocol-error? c) + ;; ITEM is not in the store; return #f. + (values #f store))) + (values (query-path-info store item) store)))) -(define (file-size* item) - "Like 'file-size', but resort to information from substitutes if ITEM is not -in the store." - (mlet %store-monad ((exists? (store-item-exists? item))) - (if exists? - (return (file-size item)) +(define (file-size item) + "Return the size in bytes of ITEM, resorting to information from substitutes +if ITEM is not in the store." + (mlet %store-monad ((info (query-path-info* item))) + (if info + (return (path-info-nar-size info)) (mlet %store-monad ((info (substitutable-path-info* (list item)))) (match info ((info) @@ -149,7 +130,7 @@ profile of ITEM and its requisites." (cons item refs)))))) (sizes (mapm %store-monad (lambda (item) - (>>= (file-size* item) + (>>= (file-size item) (lambda (size) (return (cons item size))))) refs))) |