Browse Source

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.
version-0.8.3
Ludovic Courtès 8 years ago
parent
commit
4a44d7bbc6
  1. 7
      doc/guix.texi
  2. 18
      guix/ui.scm
  3. 4
      tests/ui.scm

7
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},

18
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)))))))

4
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 ()

Loading…
Cancel
Save