Subject: bug#70593: 30.0.50; Dired: buffers of renamed dirs are broken

From: Michael Heerdegen <[email-masked]>
Date: Thu, 09 May 2024 16:05:11 +0200

Michael Heerdegen via "Bug reports for GNU Emacs, the Swiss army knife
of text editors" <[email-masked]> writes:

> > (1) What do we need to do we do when `dired-directory' is a cons
> > (i.e. dir along with a file list)?

Here is an update of the former patch doing the minimum in that case:
update only the car of a consp `dired-directory' when the car is
affected by the renaming, and leave the rest untouched:

From 30d1546d30a75f5ff52a7aad10063c49a5e76789 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <[email-masked]>
Date: Mon, 29 Apr 2024 16:10:29 +0200
Subject: [PATCH] WIP: Try to fix #70593

---
 lisp/dired-aux.el | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index e340f98a551..9c7cd8aa1f4 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -2331,18 +2331,25 @@ dired-rename-subdir-1
       (if (dired-in-this-tree-p (car elt) expanded-dir)
 	  ;; ELT's subdir is affected by the rename
 	  (dired-rename-subdir-2 elt dir to)))
-    (if (equal dir default-directory)
+    (if (string= dir (expand-file-name default-directory))
 	;; if top level directory was renamed, lots of things have to be
 	;; updated:
 	(progn
 	  (dired-unadvertise dir)	; we no longer dired DIR...
-	  (setq default-directory to
-		dired-directory (expand-file-name;; this is correct
-				 ;; with and without wildcards
-				 (file-name-nondirectory (if (stringp dired-directory)
-                                                             dired-directory
-                                                           (car dired-directory)))
-				 to))
+	  (let* ((dired-dir (if (stringp dired-directory)
+                                dired-directory
+                              (car dired-directory)))
+                 (dired-dir-new
+                  (abbreviate-file-name
+                   (file-name-as-directory
+                    (expand-file-name ;; this is correct
+		     ;; with and without wildcards
+		     (file-name-nondirectory dired-dir)
+		     to)))))
+            (if (stringp dired-directory)
+                (setq dired-directory dired-dir-new)
+              (setcar dired-directory dired-dir-new))
+            (setq default-directory dired-dir-new))
 	  (let ((new-name (file-name-nondirectory
 			   (directory-file-name (if (stringp dired-directory)
                                                     dired-directory
--
2.39.2

Michael.