summaryrefslogtreecommitdiff
path: root/guix/ui.scm
diff options
context:
space:
mode:
authorEfraim Flashner <efraim@flashner.co.il>2025-06-29 10:21:12 +0300
committerEfraim Flashner <efraim@flashner.co.il>2025-07-28 13:57:53 +0300
commitcc588d8eb6a5e05bc8c9d41855685a1d8ce70187 (patch)
tree8f1091354927a109b82ba558dd7637061479b787 /guix/ui.scm
parentcf6868187a68feea41b3cde9bd37670df7192fed (diff)
guix gc: Adjust size suffix based on the amount of data.
* guix/ui.scm (number->size): New procedure. * guix/scripts/gc.scm (guix-gc)[actions]: Display the amount of collected-garbage using more specific units. [ensure-free-space]: Display the size using an appropriate size unit. * nix/libstore/gc.cc (deletePathRecursive, removeUnusedLinks): Same. * nix/libstore/optimise-store.cc (showBytes): Move function ... * nix/libstore/misc.cc: ... to here. Expand to adjust the output based on the amount of bytes received. Change-Id: Idceb1a13f8e45f959d327f53d1a8accb29d2678b
Diffstat (limited to 'guix/ui.scm')
-rw-r--r--guix/ui.scm30
1 files changed, 30 insertions, 0 deletions
diff --git a/guix/ui.scm b/guix/ui.scm
index cd9eb1013d..d6d5eb9dcd 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -19,6 +19,7 @@
;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com>
;;; Copyright © 2022 Taiju HIGASHI <higashi@taiju.info>
;;; Copyright © 2022 Liliana Marie Prikler <liliana.prikler@gmail.com>
+;;; Copyright © 2025 Efraim Flashner <efraim@flashner.co.il>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -99,6 +100,7 @@
make-regexp*
string->number*
size->number
+ number->size
show-derivation-outputs
build-notifier
show-what-to-build
@@ -695,6 +697,34 @@ interpreted."
(x
(leave (G_ "unknown unit: ~a~%") unit)))))))
+(define (number->size num)
+ "Convert NUM, an integer number of bytes, to a human readable string using
+common storage prefixes."
+ (define (pretty-print-number number exponent)
+ (number->string (inexact->exact (round (/ number (expt 2 exponent))))))
+
+ (unless (number? num)
+ (leave (G_ "invalid number: ~a~%") (object->string num)))
+
+ (cond
+ ((> num (expt 2 80))
+ (string-append (pretty-print-number num 80) " YiB"))
+ ((> num (expt 2 70))
+ (string-append (pretty-print-number num 70) " ZiB"))
+ ((> num (expt 2 60))
+ (string-append (pretty-print-number num 60) " EiB"))
+ ((> num (expt 2 50))
+ (string-append (pretty-print-number num 50) " PiB"))
+ ((> num (expt 2 40))
+ (string-append (pretty-print-number num 40) " TiB"))
+ ((> num (expt 2 30))
+ (string-append (pretty-print-number num 30) " GiB"))
+ ((> num (expt 2 20))
+ (string-append (pretty-print-number num 20) " MiB"))
+ ((> num (expt 2 10))
+ (string-append (pretty-print-number num 10) " KiB"))
+ (#t (string-append (number->string num) " bytes"))))
+
(define (display-collision-resolution-hint collision)
"Display hints on how to resolve COLLISION, a &profile-collistion-error."
(define (top-most-entry entry)