Subject: Re: bug#31489: 25.3; Dired unable to open directory "/ssh:example.com"

From: Michael Albinus <[email-masked]>
Date: Fri, 18 May 2018 17:25:17 +0200

Christoph Michelbach <[email-masked]> writes:

Hi Christoph,

> When a file's path conflicts with how an external resource is
> addressed, you can tell Emacs to open the local path by preceding it
> with "/:". If you created a file with
>
> sudo touch "/ssh:example.com/file"
>
> , you could access it via:
>
> C-x C-f /:/ssh:example.com/file RET
>
> However, if you leave "file" out, you don't get to see a dired buffer after
> hitting return. Instead, the current windows are retained and the mini buffer
> reads:
>
> Host name must not match method "ssh"

Thanks for the bug report. The appended patch, towards the master branch
of the Emacs repository, fixes it for me. Could you pls check?

> You also cannot first navigate to "/" and then enter the directory by moving
> point to it and hitting return. The same problem accompanied by the same error
> message occurs.

You should navigate to "/:". Then it works, after applying the patch.

However, before committing the patch I need to run further tests. The
patch let tramp-tests.el fail, which must be investigated further.

Best regards, Michael.

diff --git a/lisp/files.el b/lisp/files.el
index d98d09bb1e..2478a22046 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7056,7 +7056,8 @@ file-name-non-special
 		   '(nil 0))))
 	 method
 	 ;; Copy ARGUMENTS so we can replace elements in it.
-	 (arguments (copy-sequence arguments)))
+	 (arguments (copy-sequence arguments))
+         file-name-handler-alist)
     (if (symbolp (car file-arg-indices))
 	(setq method (pop file-arg-indices)))
     ;; Strip off the /: from the file names that have it.
@@ -7064,27 +7065,20 @@ file-name-non-special
       (while (consp file-arg-indices)
 	(let ((pair (nthcdr (car file-arg-indices) arguments)))
 	  (and (car pair)
-	       (string-match "\\`/:" (car pair))
-	       (setcar pair
-		       (if (= (length (car pair)) 2)
-			   "/"
-			 (substring (car pair) 2)))))
+	       (setcar pair (file-name-unquote (car pair)))))
 	(setq file-arg-indices (cdr file-arg-indices))))
     (pcase method
       (`identity (car arguments))
       (`add (file-name-quote (apply operation arguments)))
       (`buffer-file-name
-       (let ((buffer-file-name
-              (if (string-match "\\`/:" buffer-file-name)
-                  (substring buffer-file-name (match-end 0))
-                buffer-file-name)))
+       (let ((buffer-file-name (file-name-unquote buffer-file-name)))
          (apply operation arguments)))
       (`insert-file-contents
        (let ((visit (nth 1 arguments)))
          (unwind-protect
              (apply operation arguments)
            (when (and visit buffer-file-name)
-             (setq buffer-file-name (concat "/:" buffer-file-name))))))
+             (setq buffer-file-name (file-name-quote buffer-file-name))))))
       (`unquote-then-quote
        ;; We can't use `cl-letf' with `(buffer-local-value)' here
        ;; because it wouldn't work during bootstrapping.
@@ -7093,7 +7087,7 @@ file-name-non-special
          ;; `verify-visited-file-modtime' action, which takes a buffer
          ;; as only optional argument.
          (with-current-buffer (or (car arguments) buffer)
-           (let ((buffer-file-name (substring buffer-file-name 2)))
+           (let ((buffer-file-name (file-name-unquote buffer-file-name)))
              ;; Make sure to hide the temporary buffer change from the
              ;; underlying operation.
              (with-current-buffer buffer