aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-10-03 13:35:14 +0200
committerLudovic Courtès <ludo@gnu.org>2014-10-03 18:03:09 +0200
commit4a44d7bbc68ff3e363e6c166a588474cbd6c20f8 (patch)
tree05527f5ad13ba290127c5db1e516a3298b7dda1c
parent882383a9aa5fbeef6f29d359a786a6db7c9e03db (diff)
downloadgnu-guix-4a44d7bbc68ff3e363e6c166a588474cbd6c20f8.tar
gnu-guix-4a44d7bbc68ff3e363e6c166a588474cbd6c20f8.tar.gz
ui: Recognize the same size units as Coreutils.
* 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.
-rw-r--r--doc/guix.texi7
-rw-r--r--guix/ui.scm18
-rw-r--r--tests/ui.scm4
3 files changed, 21 insertions, 8 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 57806cebe1..5e8f8e6eb5 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -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},
diff --git a/guix/ui.scm b/guix/ui.scm
index 531d922ad9..04345d4770 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -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)))))))
diff --git a/tests/ui.scm b/tests/ui.scm
index 7cc02649e1..db90cdd479 100644
--- a/tests/ui.scm
+++ b/tests/ui.scm
@@ -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 ()