From 48eb6af0f78424df9f02d744275538d80cee3bc4 Mon Sep 17 00:00:00 2001
From: Harm van der Vegt <harmvegt@gmail.com>
Date: Sat, 31 Aug 2024 20:10:37 +0200
Subject: [PATCH] Make chart-space-usage OS independent

---
 lisp/emacs-lisp/chart.el | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/lisp/emacs-lisp/chart.el b/lisp/emacs-lisp/chart.el
index da61e45213d..c195ccb7165 100644
--- a/lisp/emacs-lisp/chart.el
+++ b/lisp/emacs-lisp/chart.el
@@ -646,30 +646,22 @@ SORT-PRED if desired."
   (interactive "DDirectory: ")
   (message "Collecting statistics...")
   (let ((nmlst nil)
-	(cntlst nil)
-	(b (get-buffer-create " *du-tmp*")))
-    (set-buffer b)
-    (erase-buffer)
-    (insert "cd " d ";du -sk * \n")
-    (message "Running `cd %s;du -sk *'..." d)
-    (call-process-region (point-min) (point-max) shell-file-name t
-			 (current-buffer) nil)
-    (goto-char (point-min))
-    (message "Scanning output ...")
-    (while (re-search-forward "^\\([0-9]+\\)[ \t]+\\([^ \n]+\\)$" nil t)
-      (let* ((nam (buffer-substring (match-beginning 2) (match-end 2)))
-	     (num (buffer-substring (match-beginning 1) (match-end 1))))
-	(setq nmlst (cons nam nmlst)
-	      ;; * 1000 to put it into bytes
-	      cntlst (cons (* (string-to-number num) 1000) cntlst))))
+        (cntlst nil))
+    (dolist (file (directory-files d t))
+      (when (file-regular-p file)
+        (let ((size (nth 7 (file-attributes file))))
+          (setq nmlst (cons (file-name-nondirectory file) nmlst))
+          (setq cntlst (cons size cntlst)))))
+
     (if (not nmlst)
-	(error "No files found!"))
+        (error "No files found!"))
+
+    ;; Display the chart if files are found
     (chart-bar-quickie 'vertical (format "Largest files in %s" d)
-		       nmlst "File Name"
-		       cntlst "File Size"
-		       10
-		       (lambda (a b) (> (cdr a) (cdr b))))
-    ))
+                       nmlst "File Name"
+                       cntlst "File Size"
+                       10
+                       (lambda (a b) (> (cdr a) (cdr b))))))
 
 (defun chart-emacs-storage ()
   "Chart the current storage requirements of Emacs."
-- 
2.11.0.windows.3

