[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/02: size: Get the item's size from the daemon rather than compute it.
From: |
Ludovic Courtès |
Subject: |
02/02: size: Get the item's size from the daemon rather than compute it. |
Date: |
Wed, 19 Aug 2015 09:39:56 +0000 |
civodul pushed a commit to branch master
in repository guix.
commit 83bde59fb3db5827002a0049a5571e4163af5ff1
Author: Ludovic Courtès <address@hidden>
Date: Wed Aug 19 11:33:51 2015 +0200
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'.
---
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 92625d8..ee070f1 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)))