Subject: bug#54542: closed (Re: bug#54542: 29.0.50; dired can't visit a local directory if another buffer visits an unreachable remote (TRAMP) directory)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 26 Mar 2022 10:59:02 +0000

Your bug report

#54542: 29.0.50; dired can't visit a local directory if another buffer visits an unreachable remote (TRAMP) directory

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
54542: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=54542
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#54542: 29.0.50; dired can't visit a local directory if another buffer visits an unreachable remote (TRAMP) directory
From: Michael Albinus <[email-masked]>
To: Dima Kogan <[email-masked]>
Cc: [email-masked]
Date: Sat, 26 Mar 2022 11:57:59 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Version: 29.1

Dima Kogan <[email-masked]> writes:

Hi Dima,

>> We have already variable non-essential, which shall help for
>> non-existing / broken connections. While I could reproduce your
>> initial recipe locally, the attached patch cures it for me. Could you,
>> please, test?
>
> Hi Michael. Your patch fixes the issue. Thanks for looking into this!

Thanks for the feedback. I've committed this to Emacs master, closing
the bug.

Best regards, Michael.

Subject: 29.0.50; dired can't visit a local directory if another buffer visits an unreachable remote (TRAMP) directory
From: Dima Kogan <[email-masked]>
To: [email-masked]
Date: Thu, 24 Mar 2022 00:15:10 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi. This sounds convoluted, but it's a real-life bug I hit repeatedly.
Recipe:

1. emacs -Q

2. C-x C-f /ssh:host:directory

   Visit some remote directory via TRAMP. This opens a dired buffer

3. Unplug the network cable. Or walk away from wifi. Or turn off the
   remote host. Optionally, do other stuff with emacs. The bug is hit if
   the buffer in step 2 is open somewhere; doesn't have to be visible

4. C-x C-f /some/local/directory

One would expect step 4 to work just fine because it's a local
directory, so no TRAMP business should affect it, but it does. Step 4
will try to connect to the host in step 2. But that host is gone, so
it'll fail, and step 4 will fail too.

The problem is here:

  (defun dired-find-buffer-nocreate (dirname &optional mode)
      ....
      (let (found (blist dired-buffers))
        ...
        (while blist
            ...
            (with-current-buffer (cdr (car blist))
            ....
                              (expand-file-name
                               (if (consp dired-directory)
                                   (car dired-directory)
                                 dired-directory))))

Here dired is trying to figure out if we're already visiting the
requested directory. In doing so, it loops through all extant dired
buffers, and runs (expand-file-name) on each one. Running
(expand-file-name) on a remote directory will try to contact the host.

I'm not attaching a patch because I'm not 100% sure what's appropriate.
I guess we want to replace

  (expand-file-name dired-directory)

with something like this pseudo-code

  (concat (tramp-host dired-directory)
          (expand-file-name (tramp-filename dired-directory)))

Except, thinking about edge cases: making sure this works with/without
TRAMP, making sure relative directories work right, etc, etc.

Do we already have a function that does this?

Thanks!