]> git.eshelyaron.com Git - emacs.git/commitdiff
When using Eshell's "du" implementation, deduplicate hard links
authorJim Porter <jporterbugs@gmail.com>
Sun, 10 Nov 2024 00:06:34 +0000 (16:06 -0800)
committerEshel Yaron <me@eshelyaron.com>
Mon, 11 Nov 2024 10:27:01 +0000 (11:27 +0100)
* lisp/eshell/em-unix.el (eshell-du-sum-directory): Take SEEN-FILES.
(eshell/du): Create 'seen-files' hash table.

(cherry picked from commit 1704fa4fb4164a15c7e258b922dbba190811d92d)

lisp/eshell/em-unix.el

index 74d61e82befe28227669940c1d4c99310a835620..9cdc0ca6f25576d36e6634af65681773d27452e3 100644 (file)
@@ -860,11 +860,15 @@ external command."
 
 (cl-defun eshell-du-sum-directory (path depth-remaining &rest args
                                    &key print-function show-all
-                                   dereference-links only-one-filesystem)
+                                   dereference-links only-one-filesystem
+                                   seen-files)
   "Summarize PATH, and its member directories."
   (let ((size 0.0))
     (dolist (entry (eshell-directory-files-and-attributes path))
-      (unless (string-match "\\`\\.\\.?\\'" (car entry))
+      (unless (or (string-match "\\`\\.\\.?\\'" (car entry))
+                  (gethash (file-attribute-file-identifier (cdr entry))
+                           seen-files))
+        (puthash (file-attribute-file-identifier (cdr entry)) t seen-files)
         (let* ((file-name (concat path "/" (car entry)))
                (file-type (file-attribute-type (cdr entry)))
                (symlink (and (stringp file-type) file-type)))
@@ -938,6 +942,7 @@ Summarize disk usage of each FILE, recursively for directories.")
      (when (eshell-under-windows-p)
        (setq only-one-filesystem nil))
      (let ((size 0.0)
+           (seen-files (make-hash-table :test #'equal))
            (print-function
             (lambda (size name)
               (let ((size-str (eshell-printable-size size human-readable
@@ -952,7 +957,8 @@ Summarize disk usage of each FILE, recursively for directories.")
                              (directory-file-name arg) max-depth
                              :print-function print-function :show-all show-all
                              :dereference-links dereference-links
-                             :only-one-filesystem only-one-filesystem))))
+                             :only-one-filesystem only-one-filesystem
+                             :seen-files seen-files))))
        (when grand-total
          (funcall print-function size "total"))))))