ui: Recognize the same size units as Coreutils.
authorLudovic Courtès <ludo@gnu.org>
Fri, 3 Oct 2014 11:35:14 +0000 (13:35 +0200)
committerLudovic Courtès <ludo@gnu.org>
Fri, 3 Oct 2014 16:03:09 +0000 (18:03 +0200)
* guix/ui.scm (size->number): Add a bunch of large units.  Recognize
  one-letter unit names.  Change "KB" to "kB".
* tests/ui.scm ("size->number, 1T"): New test.
* doc/guix.texi (Invoking guix gc): Add cross-reference to "Block size"
  in the Coreutils manual.
  (Invoking guix system): Likewise.

doc/guix.texi
guix/ui.scm
tests/ui.scm

index 57806ce..5e8f8e6 100644 (file)
@@ -1142,7 +1142,8 @@ specified.
 
 When @var{min} is given, stop once @var{min} bytes have been collected.
 @var{min} may be a number of bytes, or it may include a unit as a
-suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes.
+suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
+(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
 
 When @var{min} is omitted, collect all the garbage.
 
@@ -3822,8 +3823,8 @@ This works as per @command{guix build} (@pxref{Invoking guix build}).
 @item --image-size=@var{size}
 For the @code{vm-image} and @code{disk-image} actions, create an image
 of the given @var{size}.  @var{size} may be a number of bytes, or it may
-include a unit as a suffix, such as @code{MiB} for mebibytes and
-@code{GB} for gigabytes.
+include a unit as a suffix (@pxref{Block size, size specifications,,
+coreutils, GNU Coreutils}).
 @end table
 
 Note that all the actions above, except @code{build} and @code{init},
index 531d922..04345d4 100644 (file)
@@ -189,14 +189,22 @@ interpreted."
     ((compose inexact->exact round)
      (* num
         (match unit
-          ("KiB" (expt 2 10))
-          ("MiB" (expt 2 20))
-          ("GiB" (expt 2 30))
-          ("TiB" (expt 2 40))
-          ("KB"  (expt 10 3))
+          ((or "KiB" "K" "k") (expt 2 10))
+          ((or "MiB" "M")     (expt 2 20))
+          ((or "GiB" "G")     (expt 2 30))
+          ((or "TiB" "T")     (expt 2 40))
+          ((or "PiB" "P")     (expt 2 50))
+          ((or "EiB" "E")     (expt 2 60))
+          ((or "ZiB" "Z")     (expt 2 70))
+          ((or "YiB" "Y")     (expt 2 80))
+          ("kB"  (expt 10 3))
           ("MB"  (expt 10 6))
           ("GB"  (expt 10 9))
           ("TB"  (expt 10 12))
+          ("PB"  (expt 10 15))
+          ("EB"  (expt 10 18))
+          ("ZB"  (expt 10 21))
+          ("YB"  (expt 10 24))
           (""    1)
           (_
            (leave (_ "unknown unit: ~a~%") unit)))))))
index 7cc0264..db90cdd 100644 (file)
@@ -189,6 +189,10 @@ Second line" 24))
   (inexact->exact (round (* 1.2 (expt 2 30))))
   (size->number "1.2GiB"))
 
+(test-equal "size->number, 1T"
+  (expt 2 40)
+  (size->number "1T"))
+
 (test-assert "size->number, invalid unit"
   (catch 'quit
     (lambda ()