aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Porter2024-11-09 16:06:34 -0800
committerJim Porter2024-11-09 17:01:34 -0800
commit1704fa4fb4164a15c7e258b922dbba190811d92d (patch)
tree663adb3bf5e6f0c3b0918b4f1e1373521cebdab8
parent37c583a2c2f97c6fb0ed0433db9c74c6a1758e3e (diff)
downloademacs-1704fa4fb4164a15c7e258b922dbba190811d92d.tar.gz
emacs-1704fa4fb4164a15c7e258b922dbba190811d92d.zip
When using Eshell's "du" implementation, deduplicate hard links
* lisp/eshell/em-unix.el (eshell-du-sum-directory): Take SEEN-FILES. (eshell/du): Create 'seen-files' hash table.
-rw-r--r--lisp/eshell/em-unix.el12
1 files changed, 9 insertions, 3 deletions
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el
index 74d61e82bef..9cdc0ca6f25 100644
--- a/lisp/eshell/em-unix.el
+++ b/lisp/eshell/em-unix.el
@@ -860,11 +860,15 @@ external command."
860 860
861(cl-defun eshell-du-sum-directory (path depth-remaining &rest args 861(cl-defun eshell-du-sum-directory (path depth-remaining &rest args
862 &key print-function show-all 862 &key print-function show-all
863 dereference-links only-one-filesystem) 863 dereference-links only-one-filesystem
864 seen-files)
864 "Summarize PATH, and its member directories." 865 "Summarize PATH, and its member directories."
865 (let ((size 0.0)) 866 (let ((size 0.0))
866 (dolist (entry (eshell-directory-files-and-attributes path)) 867 (dolist (entry (eshell-directory-files-and-attributes path))
867 (unless (string-match "\\`\\.\\.?\\'" (car entry)) 868 (unless (or (string-match "\\`\\.\\.?\\'" (car entry))
869 (gethash (file-attribute-file-identifier (cdr entry))
870 seen-files))
871 (puthash (file-attribute-file-identifier (cdr entry)) t seen-files)
868 (let* ((file-name (concat path "/" (car entry))) 872 (let* ((file-name (concat path "/" (car entry)))
869 (file-type (file-attribute-type (cdr entry))) 873 (file-type (file-attribute-type (cdr entry)))
870 (symlink (and (stringp file-type) file-type))) 874 (symlink (and (stringp file-type) file-type)))
@@ -938,6 +942,7 @@ Summarize disk usage of each FILE, recursively for directories.")
938 (when (eshell-under-windows-p) 942 (when (eshell-under-windows-p)
939 (setq only-one-filesystem nil)) 943 (setq only-one-filesystem nil))
940 (let ((size 0.0) 944 (let ((size 0.0)
945 (seen-files (make-hash-table :test #'equal))
941 (print-function 946 (print-function
942 (lambda (size name) 947 (lambda (size name)
943 (let ((size-str (eshell-printable-size size human-readable 948 (let ((size-str (eshell-printable-size size human-readable
@@ -952,7 +957,8 @@ Summarize disk usage of each FILE, recursively for directories.")
952 (directory-file-name arg) max-depth 957 (directory-file-name arg) max-depth
953 :print-function print-function :show-all show-all 958 :print-function print-function :show-all show-all
954 :dereference-links dereference-links 959 :dereference-links dereference-links
955 :only-one-filesystem only-one-filesystem)))) 960 :only-one-filesystem only-one-filesystem
961 :seen-files seen-files))))
956 (when grand-total 962 (when grand-total
957 (funcall print-function size "total")))))) 963 (funcall print-function size "total"))))))
958 964