Subject: bug#50630: 28.0.50; list-directory shows free space for current directory, not the specified one

From: John Cummings <[email-masked]>
Date: Thu, 16 Sep 2021 23:00:50 +0000

Hello, long time emacs user; first time reporter. Apologies if I do anything wrong here.

The verbose output for list-directory always shows the free space for the current directory of the buffer where it was called, not the target directory that is supplied as an argument.

This may have been first introduced in 849051903e7, while fixing this report:
https://lists.gnu.org/archive/html/bug-gnu-emacs/2002-03/msg00251.html
The result was that, while the *Directory* output buffer's current directory was set correctly, setting it last meant that the free space calculation always took place in "." rather than the argument to list-directory.

Here are commands/output to demonstrate. Note that the free space changes for the same directory argument when I change the current directory, since the two different directories are on different disks.

  (eval-expression (pwd) t)
  "Directory ~/emacs/"

  (eval-expression (list-directory "~" t) t)
  "/home/emacsdev/"

  (insert-buffer-substring "*Directory*")
  Directory /home/emacsdev
  total used in directory 0 available 15.5 GiB
  lrwxrwxrwx 1 /emacsdev /emacsdev 26 Sep 16 17:45 emacs -> /media/ubuntu/turkey/emacs
  lrwxrwxrwx 1 /emacsdev /emacsdev 34 Sep 16 17:44 emacs-project -> /media/ubuntu/turkey/emacs-project

  (cd "/")

  (eval-expression (pwd) t)
  "Directory /"

  (eval-expression (list-directory "~" t) t)
  "/home/emacsdev/"

  (insert-buffer-substring "*Directory*")
  Directory /home/emacsdev
  total used in directory 0 available 7.7 GiB
  lrwxrwxrwx 1 /emacsdev /emacsdev 26 Sep 16 17:45 emacs -> /media/ubuntu/turkey/emacs
  lrwxrwxrwx 1 /emacsdev /emacsdev 34 Sep 16 17:44 emacs-project -> /media/ubuntu/turkey/emacs-project

Changing the call to get-free-disk-space seemed to work in the attached patch, but I haven't attempted to dig deeper and check for any regressions. I would be glad to do that, but would need more time to research and would probably ask for more help to do it.

Thanks for everything!

In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
 of 2021-09-10 built on ubuntu
Repository revision: ceb60225bacc7650b5e52032c0c33b9d67f9a6d7
Repository branch: master
System Description: Ubuntu 20.04.1 LTS

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG
LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG SECCOMP SOUND
THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg rfc6068 epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map time-date mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils subr-x pcase
misearch multi-isearch vc-git diff-mode easy-mmode vc-dispatcher
bug-reference find-func cl-extra shortdoc text-property-search seq
mule-diag thingatpt help-fns radix-tree help-mode cl-loaddefs cl-lib
term/xterm xterm byte-opt gv bytecomp byte-compile cconv iso-transl
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 99674 10407)
 (symbols 48 8011 1)
 (strings 32 25795 958)
 (string-bytes 1 846999)
 (vectors 16 13457)
 (vector-slots 8 152638 6184)
 (floats 8 90 749)
 (intervals 56 1088 62)
 (buffers 992 16))

From 87dbf73c209e70382db64c2d196b761d656df409 Mon Sep 17 00:00:00 2001
From: emacs dev <[email-masked]>
Date: Thu, 16 Sep 2021 18:49:43 -0400
Subject: [PATCH] text verbose dir fix

---
 lisp/files.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/files.el b/lisp/files.el
index 7e4bdab507..ef0c4ac458 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7608,7 +7608,7 @@ insert-directory
 		  ;; Replace "total" with "total used in directory" to
 		  ;; avoid confusion.
 		  (replace-match "total used in directory" nil nil nil 1)
-		  (let ((available (get-free-disk-space ".")))
+		  (let ((available (get-free-disk-space file)))
 		    (when available
 		      (end-of-line)
 		      (insert " available " available))))))))))
-- 
2.25.1