From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#72919: 29.1; chart-space-usage in chart.el does not work correctly on windows Date: Sun, 01 Sep 2024 21:35:03 +0300 Message-ID: <86bk179q94.fsf@gnu.org> References: <86seujaj0r.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33984"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 72919@debbugs.gnu.org To: Harm Van der Vegt Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 01 20:36:28 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1skpR4-0008bT-2N for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 01 Sep 2024 20:36:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1skpQi-0000fS-8n; Sun, 01 Sep 2024 14:36:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1skpQg-0000fH-ML for bug-gnu-emacs@gnu.org; Sun, 01 Sep 2024 14:36:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1skpQg-0002V7-DG for bug-gnu-emacs@gnu.org; Sun, 01 Sep 2024 14:36:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=P5p3eSfeoxJjNNgpm0hsioNij3TjBeuBLQU19JgSF6o=; b=XSplEiusrvIHxsELtLPNmMOKdugJM90O+GFMYhnxYJULmqsIvfTgYdglpxIkmrKiPrGJ1tsTWpiQv/vJeWxkYxAjyJVHRDsNvpiuKk6nlrzpiClP97ZBd5P52vZMDx6AYw2nYcsYNV3/XVqpXsGEl8gyH1tv+Yz0+MASlMHVFiRTqjoTTl1AwHmWLl8PxDthjcWmB8FK5QfEGksnR5O2ZckEpE+hvbO4a2U/KD3EL5j2OWgSS+G37GSy0TGdyCcHEV5MDZjIk3qKurCaXg4dLCOyHbjeNP6Q77+r8zei6U+G18P9BX+hiSUHAu+3oA7YFMhzjMKgFSJ5IZxhgGX6TQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1skpRd-0001KZ-Ni for bug-gnu-emacs@gnu.org; Sun, 01 Sep 2024 14:37:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Sep 2024 18:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72919 X-GNU-PR-Package: emacs Original-Received: via spool by 72919-submit@debbugs.gnu.org id=B72919.17252157755052 (code B ref 72919); Sun, 01 Sep 2024 18:37:01 +0000 Original-Received: (at 72919) by debbugs.gnu.org; 1 Sep 2024 18:36:15 +0000 Original-Received: from localhost ([127.0.0.1]:38549 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1skpQt-0001JP-7T for submit@debbugs.gnu.org; Sun, 01 Sep 2024 14:36:15 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:45854) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1skpQq-0001J8-Lr for 72919@debbugs.gnu.org; Sun, 01 Sep 2024 14:36:13 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1skpPn-0002Ol-FY; Sun, 01 Sep 2024 14:35:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=P5p3eSfeoxJjNNgpm0hsioNij3TjBeuBLQU19JgSF6o=; b=VUSNz9U3wGYe DH7bgQj8bzL0OxmycLZX2Ynghh43Nrp471hdasKnYBcgjkFXdYTMfEmHDbyUt+4hKpz7fx/u/1tC4 2xjH8lqryDRN3O86A/Sr3q62gKemNz6Uk9gWL7fYqY0R1dZPaxMLsU1p83a38Xg6oW5WzlnlivTpD wdt6mpK8xI9Ji70/Jrs5Fbjx+PFB8QNQYUZnDv4jPLU+7uo36lqvfj0lZaxwbui7EBjaUybGybFAN 9LRu7Y+MsgyuiPnPklshV1dzoV0xNLtINBzGvWOYGaD3c+jam5l3X1Y4m57Ryh4tIsTLdX9Trp3xZ 7/DhgTZxqnidJ7xkgQMI5A==; In-Reply-To: (message from Harm Van der Vegt on Sun, 1 Sep 2024 20:11:39 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:291068 Archived-At: [Please use Reply All to reply, so that the bug tracker is CC'ed.] > From: Harm Van der Vegt > Date: Sun, 1 Sep 2024 20:11:39 +0200 > > >Thanks. However, I think your changes are not entirely correct: they > >fail to account for space usage of files inside subdirectories of the > >directory which the user types at the prompt, whereas the > >implementation with "du" does account for that. > > That is indeed a pretty major difference, my bad! > > >In addition, I think if someone has 'du' on Windows, it should be used. > > Is there a preference for using system binaries above elisp for cases like these? I think 'du' has some tricks up its sleeve (like accounting correctly for block size), which a Lisp implementation can only approximate. I don't think minor differences matter here, since this command is just an illustration of what chart.el can be used for, but I do want to use 'du' if it's available. > >So I came up with the following changes instead. Could you please try > >them, both with and without du.exe on PATH? If these changes give > >good results, I will install them. > > Thanks. > > I've tried your changes with and without du. This uncovered something in the > original implementation, namely that the original implementation did not count > hidden files and directories. du * skips dotfiles for me. > > With du present chart-space-usage shows the lisp directory as the largest in the > emacs repository root. Without du it shows .git as the largest. This just means minor adjustments in the code I posted: we need to use a different regexp in the call to directory-files-recursively, and also ignore files that start with a dot in the command itself. I will make those changes, thanks for pointing them out > I'm not sure which output is the wanted output. I think we want to be as close to 'du' as possible. > I've attempted to find a shell independent way to have du show dotfiles, but it > appears to be rather tricky. I don't think we want that. > I've made a new patch that makes the elisp implementation recursive, uses the > rounding function provided by you and shows dotfiles. I'd prefer to avoid recursion (in addition to what directory-files-recursively already does), because that could overflow the stack. I will post a version that ignores dotfiles. Here's the version you sent, repeated for the bug tracker: >>From 6f53d65f9ae5e1c61a2ca2650b149c895ce9794c Mon Sep 17 00:00:00 2001 >From: Harm van der Vegt Date: Sun, 1 Sep 2024 20:03:34 +0200 Subject: [PATCH] Make chart-space-usage OS and shell independent --- lisp/emacs-lisp/chart.el | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/lisp/emacs-lisp/chart.el b/lisp/emacs-lisp/chart.el index c195ccb7165..b0302b55278 100644 --- a/lisp/emacs-lisp/chart.el +++ b/lisp/emacs-lisp/chart.el @@ -641,27 +641,44 @@ SORT-PRED if desired." (lambda (a b) (> (cdr a) (cdr b)))) )) +;; This assumes 4KB blocks +(defun chart--file-size (size) + (* (/ (+ size 4095) 4096) 4096)) + +(defun chart--directory-size (dir) + "Compute total size of files in directory DIR and its subdirectories. +DIR is assumed to be a directory, verified by the caller." + (let ((total-size 0)) + (dolist (file (directory-files dir t directory-files-no-dot-files-regexp)) + (cond + ((file-regular-p file) + (setq total-size (+ total-size (chart--file-size (nth 7 (file-attributes file)))))) + ((file-directory-p file) + (setq total-size (+ total-size (chart--directory-size file)))))) + total-size)) + (defun chart-space-usage (d) "Display a top usage chart for directory D." (interactive "DDirectory: ") (message "Collecting statistics...") (let ((nmlst nil) - (cntlst nil)) - (dolist (file (directory-files d t)) - (when (file-regular-p file) - (let ((size (nth 7 (file-attributes file)))) + (cntlst nil)) + + (dolist (file (directory-files d t directory-files-no-dot-files-regexp)) + (let ((size (if (file-regular-p file) + (nth 7 (file-attributes file)) + (chart--directory-size file)))) (setq nmlst (cons (file-name-nondirectory file) nmlst)) - (setq cntlst (cons size cntlst))))) + (setq cntlst (cons (chart--file-size size) cntlst)))) (if (not nmlst) - (error "No files found!")) - - ;; Display the chart if files are found + (error "No files 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