[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 3b2b0b5f921 5/8: Fix eshell "ls" command for files larger than 1T
From: |
Stefan Kangas |
Subject: |
master 3b2b0b5f921 5/8: Fix eshell "ls" command for files larger than 1TiB |
Date: |
Sat, 5 Aug 2023 12:00:12 -0400 (EDT) |
branch: master
commit 3b2b0b5f921fd49ef0ac21e1522b0e037b80dffa
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>
Fix eshell "ls" command for files larger than 1TiB
* lisp/eshell/esh-util.el (eshell-printable-size): Fix displaying file
sizes larger than 1 TiB or 1 TB.
* test/lisp/eshell/esh-util-tests.el
(esh-util-test/eshell-printable-size)
(esh-util-test/eshell-printable-size/zero)
(esh-util-test/eshell-printable-size/terabyte)
(esh-util-test/eshell-printable-size/use-colors)
(esh-util-test/eshell-printable-size/block-size)
(esh-util-test/eshell-printable-size/human-readable-arg): New tests.
---
lisp/eshell/esh-util.el | 8 +++++++-
test/lisp/eshell/esh-util-tests.el | 31 +++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el
index 1d0f41d7b82..82b0d9fc623 100644
--- a/lisp/eshell/esh-util.el
+++ b/lisp/eshell/esh-util.el
@@ -433,6 +433,10 @@ Prepend remote identification of `default-directory', if
any."
(defun eshell-printable-size (filesize &optional human-readable
block-size use-colors)
"Return a printable FILESIZE."
+ (when (and human-readable
+ (not (= human-readable 1000))
+ (not (= human-readable 1024)))
+ (error "human-readable must be 1000 or 1024"))
(let ((size (float (or filesize 0))))
(if human-readable
(if (< size human-readable)
@@ -463,7 +467,9 @@ Prepend remote identification of `default-directory', if
any."
(if use-colors
(put-text-property 0 (length str)
'face 'bold-italic str))
- str)))))
+ str)
+ (let ((flavor (and (= human-readable 1000) 'si)))
+ (file-size-human-readable filesize flavor))))))
(if block-size
(setq size (/ size block-size)))
(format "%.0f" size))))
diff --git a/test/lisp/eshell/esh-util-tests.el
b/test/lisp/eshell/esh-util-tests.el
index 8585677e14e..fe4eb9f31dd 100644
--- a/test/lisp/eshell/esh-util-tests.el
+++ b/test/lisp/eshell/esh-util-tests.el
@@ -125,4 +125,35 @@
(should (equal (eshell-convert-to-number "123") "123"))
(should (equal (eshell-convert-to-number "1.23") "1.23"))))
+(ert-deftest esh-util-test/eshell-printable-size ()
+ (should (equal (eshell-printable-size (expt 2 16)) "65536"))
+ (should (equal (eshell-printable-size (expt 2 32)) "4294967296")))
+
+(ert-deftest esh-util-test/eshell-printable-size/zero ()
+ (should (equal (eshell-printable-size 0 1000 nil t) "0")))
+
+(ert-deftest esh-util-test/eshell-printable-size/terabyte ()
+ (should (equal (eshell-printable-size (1- (expt 2 40)) 1024 nil t) "1024G"))
+ (should (equal (eshell-printable-size (expt 2 40) 1024 nil t) "1T"))
+ (should (equal (eshell-printable-size (1- (expt 10 12)) 1000 nil t) "1000G"))
+ (should (equal (eshell-printable-size (expt 10 12) 1000 nil t) "1T")))
+
+(ert-deftest esh-util-test/eshell-printable-size/use-colors ()
+ (should (equal-including-properties
+ (eshell-printable-size (1- (expt 2 20)) 1024 nil t)
+ "1024k"))
+ (should (equal-including-properties
+ (eshell-printable-size (1- (expt 2 30)) 1024 nil t)
+ (propertize "1024M" 'face 'bold)))
+ (should (equal-including-properties
+ (eshell-printable-size (1- (expt 2 40)) 1024 nil t)
+ (propertize "1024G" 'face 'bold-italic))))
+
+(ert-deftest esh-util-test/eshell-printable-size/block-size ()
+ (should (equal (eshell-printable-size (1- (expt 2 20)) nil 4096) "256"))
+ (should (equal (eshell-printable-size (1- (expt 2 30)) nil 4096) "262144")))
+
+(ert-deftest esh-util-test/eshell-printable-size/human-readable-arg ()
+ (should-error (eshell-printable-size 0 999 nil t)))
+
;;; esh-util-tests.el ends here
- master updated (5683c4bad3c -> 8e20da1517a), Stefan Kangas, 2023/08/05
- master 25641c3e882 2/8: Add crossref to set-default-file-modes docstring, Stefan Kangas, 2023/08/05
- master 8e20da1517a 8/8: Simplify rng-substq with cl-substitute, Stefan Kangas, 2023/08/05
- master 3b2b0b5f921 5/8: Fix eshell "ls" command for files larger than 1TiB,
Stefan Kangas <=
- master ed395444504 7/8: Make eshell-redisplay into alias for redisplay, Stefan Kangas, 2023/08/05
- master 7df1adab1e1 6/8: Use file-size-human-readable in eshell, Stefan Kangas, 2023/08/05
- master ee788ab2f81 4/8: ; * lisp/eshell/esh-util.el: Delete redundant autoload., Stefan Kangas, 2023/08/05
- master 3f8db3bbe5e 1/8: image-dired: Fix gallery directory permissions, Stefan Kangas, 2023/08/05
- master 88ce2a5624b 3/8: Simplify pcomplete-uniquify-list, Stefan Kangas, 2023/08/05