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#54838: 28.1; Buffers are not updated when a directory is renamed in dired Date: Sun, 10 Apr 2022 20:14:33 +0300 Message-ID: <838rsc7tdy.fsf@gnu.org> References: <87ilrh55aj.fsf@valhala.localdomain> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37014"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 54838@debbugs.gnu.org To: Nicolas Martyanoff , Tassilo Horn Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 10 19:15:37 2022 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 1ndbA0-0009SH-F8 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Apr 2022 19:15:36 +0200 Original-Received: from localhost ([::1]:48196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndb9z-0004PC-2C for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Apr 2022 13:15:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndb9U-0004Oz-3o for bug-gnu-emacs@gnu.org; Sun, 10 Apr 2022 13:15:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47415) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ndb9S-0000CZ-Qo for bug-gnu-emacs@gnu.org; Sun, 10 Apr 2022 13:15:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ndb9S-0000g7-Mi for bug-gnu-emacs@gnu.org; Sun, 10 Apr 2022 13:15:02 -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, 10 Apr 2022 17:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54838 X-GNU-PR-Package: emacs Original-Received: via spool by 54838-submit@debbugs.gnu.org id=B54838.16496108812554 (code B ref 54838); Sun, 10 Apr 2022 17:15:02 +0000 Original-Received: (at 54838) by debbugs.gnu.org; 10 Apr 2022 17:14:41 +0000 Original-Received: from localhost ([127.0.0.1]:41312 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndb97-0000f8-4v for submit@debbugs.gnu.org; Sun, 10 Apr 2022 13:14:41 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:49106) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndb95-0000es-UY for 54838@debbugs.gnu.org; Sun, 10 Apr 2022 13:14:40 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:45664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndb90-00009J-JH; Sun, 10 Apr 2022 13:14:34 -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=DVHoiubjWpmPhUtiqCKKKkx+7HjTyXriYzsWBhdGnPk=; b=GsOVMikEE4j+ H3aLidH5OEB2rrgl6NHlrIQWk4cb5R9WrJiZVJC2U4UUHFR1FkJK+w9KPQvoABuDva+azn4cH6/QA 4uUFOg/jQ8KJBykpuADsnKJAUyEwnoGM6c677WgU78SxIVfhCW1iFBXwzAL/VD8WWIkw4D7tE3CPG Cs/oM4ZoxShU94c23TqD9xsiushrMg9it8Ev0eNyvJrmLkcTinL4ZbcpI4ej100F/uM1Ct4gszYzi 0/OUaf9l+4ImCmwJdQKFDjlXvGnePiygV/vFmv8V860n2n3xW8HFIpkqccJiebX0r5tugxg/c5cmc 9PI5nuhKzeUlbnRs7mEhoA==; Original-Received: from [87.69.77.57] (port=4207 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndb8z-0004Ki-Ui; Sun, 10 Apr 2022 13:14:34 -0400 In-Reply-To: <87ilrh55aj.fsf@valhala.localdomain> (message from Nicolas Martyanoff on Sun, 10 Apr 2022 17:25:40 +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" Xref: news.gmane.io gmane.emacs.bugs:229677 Archived-At: > From: Nicolas Martyanoff > Date: Sun, 10 Apr 2022 17:25:40 +0200 > > - C-x C-f /tmp/dir1/file > > - C-x C-s > Answer 'y' to the prompt to create the directory. At this point the > buffer 'file' visits /tmp/dir1/file, and the file exists on the disk. > > - Run dired in /tmp. > > - Rename /tmp/dir1 into /tmp/dir2, e.g. using 'R'. > > - Switch to the 'file' buffer. It still visits /tmp/dir1/file even > though the file is now located in /tmp/dir2. Please try the patch below and see if it solves the problem, including in other similar use cases. Tassilo, part of this bug is yet another fallout from replacing dired-in-this-tree-p with file-in-directory-p: the latter returns nil if its second arg doesn't exist, and in this scenario we are dealing with a directory that was already renamed to the new name. Do you agree with my proposed solution for that below? I intend to install it on the release branch, as this is a regression from Emacs 27. Thanks. diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 15f95eb..fc50cce 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -1838,22 +1838,23 @@ dired-rename-file "Rename FILE to NEWNAME. Signal a `file-already-exists' error if a file NEWNAME already exists unless OK-IF-ALREADY-EXISTS is non-nil." - (dired-handle-overwrite newname) - (dired-maybe-create-dirs (file-name-directory newname)) - (if (and dired-vc-rename-file - (vc-backend file) - (ignore-errors (vc-responsible-backend newname))) - (vc-rename-file file newname) - ;; error is caught in -create-files - (rename-file file newname ok-if-already-exists)) - ;; Silently rename the visited file of any buffer visiting this file. - (and (get-file-buffer file) - (with-current-buffer (get-file-buffer file) - (set-visited-file-name newname nil t))) - (dired-remove-file file) - ;; See if it's an inserted subdir, and rename that, too. - (when (file-directory-p file) - (dired-rename-subdir file newname))) + (let ((file-is-dir-p (file-directory-p file))) + (dired-handle-overwrite newname) + (dired-maybe-create-dirs (file-name-directory newname)) + (if (and dired-vc-rename-file + (vc-backend file) + (ignore-errors (vc-responsible-backend newname))) + (vc-rename-file file newname) + ;; error is caught in -create-files + (rename-file file newname ok-if-already-exists)) + ;; Silently rename the visited file of any buffer visiting this file. + (and (get-file-buffer file) + (with-current-buffer (get-file-buffer file) + (set-visited-file-name newname nil t))) + (dired-remove-file file) + ;; See if it's an inserted subdir, and rename that, too. + (when file-is-dir-p + (dired-rename-subdir file newname)))) (defun dired-rename-subdir (from-dir to-dir) (setq from-dir (file-name-as-directory from-dir) @@ -1866,7 +1867,13 @@ dired-rename-subdir (while blist (with-current-buffer (car blist) (if (and buffer-file-name - (file-in-directory-p buffer-file-name expanded-from-dir)) + ;; If FROM-DIR was renamed/removed, fall back to + ;; 'dired-in-this-tree-p', since + ;; 'file-in-directory-p' will punt. + (or (and (file-exists-p expanded-from-dir) + (file-in-directory-p buffer-file-name + expanded-from-dir)) + (dired-in-this-tree-p buffer-file-name expanded-from-dir))) (let ((modflag (buffer-modified-p)) (to-file (replace-regexp-in-string (concat "^" (regexp-quote from-dir)) @@ -1885,7 +1892,8 @@ dired-rename-subdir-1 (while alist (setq elt (car alist) alist (cdr alist)) - (if (file-in-directory-p (car elt) expanded-dir) + (if (or (file-in-directory-p (car elt) expanded-dir) + (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)