aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2021-07-02 14:51:23 +0200
committerMichael Albinus2021-07-02 14:51:23 +0200
commit225ca617b70d3c70376c2d9bf38ced2f2323b26e (patch)
tree34571b9c4020bc23cd6d9f3608061f667db5e7fd
parent38aa2074f84b4aec5ccc3a9b250c0dcee18157f8 (diff)
downloademacs-225ca617b70d3c70376c2d9bf38ced2f2323b26e.tar.gz
emacs-225ca617b70d3c70376c2d9bf38ced2f2323b26e.zip
Implement another fix for bug#49229
* lisp/minibuffer.el (read-file-name-default): Respect remote files. (Bug#49229) * lisp/net/tramp-sh.el (tramp-sh-handle-expand-file-name): Handle special file names on MS Windows. * lisp/net/tramp.el (tramp-file-name-handler): Revert patch. (Bug#49229)
-rw-r--r--lisp/minibuffer.el1
-rw-r--r--lisp/net/tramp-sh.el107
-rw-r--r--lisp/net/tramp.el9
3 files changed, 59 insertions, 58 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 71a2177c9b1..813ce14c59b 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3161,6 +3161,7 @@ See `read-file-name' for the meaning of the arguments."
3161 (unless val (error "No file name specified")) 3161 (unless val (error "No file name specified"))
3162 3162
3163 (if (and default-filename 3163 (if (and default-filename
3164 (not (file-remote-p dir))
3164 (string-equal val (if (consp insdef) (car insdef) insdef))) 3165 (string-equal val (if (consp insdef) (car insdef) insdef)))
3165 (setq val default-filename)) 3166 (setq val default-filename))
3166 (setq val (substitute-in-file-name val)) 3167 (setq val (substitute-in-file-name val))
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index ebd0fbfd2d9..88caa2fb7ba 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -2667,56 +2667,63 @@ the result will be a local, non-Tramp, file name."
2667 (setq dir (or dir default-directory "/")) 2667 (setq dir (or dir default-directory "/"))
2668 ;; Handle empty NAME. 2668 ;; Handle empty NAME.
2669 (when (zerop (length name)) (setq name ".")) 2669 (when (zerop (length name)) (setq name "."))
2670 ;; Unless NAME is absolute, concat DIR and NAME. 2670 ;; On MS Windows, some special file names are not returned properly
2671 (unless (file-name-absolute-p name) 2671 ;; by `file-name-absolute-p'.
2672 (setq name (concat (file-name-as-directory dir) name))) 2672 (if (and (eq system-type 'windows-nt)
2673 ;; If connection is not established yet, run the real handler. 2673 (string-match-p
2674 (if (not (tramp-connectable-p name)) 2674 (concat "^\\([[:alpha:]]:\\|" null-device "$\\)") name))
2675 (tramp-run-real-handler #'expand-file-name (list name nil)) 2675 (tramp-run-real-handler #'expand-file-name (list name dir))
2676 ;; Dissect NAME. 2676 ;; Unless NAME is absolute, concat DIR and NAME.
2677 (with-parsed-tramp-file-name name nil 2677 (unless (file-name-absolute-p name)
2678 (unless (tramp-run-real-handler #'file-name-absolute-p (list localname)) 2678 (setq name (concat (file-name-as-directory dir) name)))
2679 (setq localname (concat "~/" localname))) 2679 ;; If connection is not established yet, run the real handler.
2680 ;; Tilde expansion if necessary. This needs a shell which 2680 (if (not (tramp-connectable-p name))
2681 ;; groks tilde expansion! The function `tramp-find-shell' is 2681 (tramp-run-real-handler #'expand-file-name (list name nil))
2682 ;; supposed to find such a shell on the remote host. Please 2682 ;; Dissect NAME.
2683 ;; tell me about it when this doesn't work on your system. 2683 (with-parsed-tramp-file-name name nil
2684 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname) 2684 (unless (tramp-run-real-handler #'file-name-absolute-p (list localname))
2685 (let ((uname (match-string 1 localname)) 2685 (setq localname (concat "~/" localname)))
2686 (fname (match-string 2 localname))) 2686 ;; Tilde expansion if necessary. This needs a shell which
2687 ;; We cannot simply apply "~/", because under sudo "~/" is 2687 ;; groks tilde expansion! The function `tramp-find-shell' is
2688 ;; expanded to the local user home directory but to the 2688 ;; supposed to find such a shell on the remote host. Please
2689 ;; root home directory. On the other hand, using always 2689 ;; tell me about it when this doesn't work on your system.
2690 ;; the default user name for tilde expansion is not 2690 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
2691 ;; appropriate either, because ssh and companions might 2691 (let ((uname (match-string 1 localname))
2692 ;; use a user name from the config file. 2692 (fname (match-string 2 localname)))
2693 (when (and (string-equal uname "~") 2693 ;; We cannot simply apply "~/", because under sudo "~/" is
2694 (string-match-p "\\`su\\(do\\)?\\'" method)) 2694 ;; expanded to the local user home directory but to the
2695 (setq uname (concat uname user))) 2695 ;; root home directory. On the other hand, using always
2696 (setq uname 2696 ;; the default user name for tilde expansion is not
2697 (with-tramp-connection-property v uname 2697 ;; appropriate either, because ssh and companions might
2698 (tramp-send-command 2698 ;; use a user name from the config file.
2699 v (format "cd %s && pwd" (tramp-shell-quote-argument uname))) 2699 (when (and (string-equal uname "~")
2700 (with-current-buffer (tramp-get-buffer v) 2700 (string-match-p "\\`su\\(do\\)?\\'" method))
2701 (goto-char (point-min)) 2701 (setq uname (concat uname user)))
2702 (buffer-substring (point) (point-at-eol))))) 2702 (setq uname
2703 (setq localname (concat uname fname)))) 2703 (with-tramp-connection-property v uname
2704 ;; There might be a double slash, for example when "~/" 2704 (tramp-send-command
2705 ;; expands to "/". Remove this. 2705 v
2706 (while (string-match "//" localname) 2706 (format "cd %s && pwd" (tramp-shell-quote-argument uname)))
2707 (setq localname (replace-match "/" t t localname))) 2707 (with-current-buffer (tramp-get-buffer v)
2708 ;; Do not keep "/..". 2708 (goto-char (point-min))
2709 (when (string-match-p "^/\\.\\.?$" localname) 2709 (buffer-substring (point) (point-at-eol)))))
2710 (setq localname "/")) 2710 (setq localname (concat uname fname))))
2711 ;; No tilde characters in file name, do normal 2711 ;; There might be a double slash, for example when "~/"
2712 ;; `expand-file-name' (this does "/./" and "/../"). 2712 ;; expands to "/". Remove this.
2713 ;; `default-directory' is bound, because on Windows there would 2713 (while (string-match "//" localname)
2714 ;; be problems with UNC shares or Cygwin mounts. 2714 (setq localname (replace-match "/" t t localname)))
2715 (let ((default-directory (tramp-compat-temporary-file-directory))) 2715 ;; Do not keep "/..".
2716 (tramp-make-tramp-file-name 2716 (when (string-match-p "^/\\.\\.?$" localname)
2717 v (tramp-drop-volume-letter 2717 (setq localname "/"))
2718 (tramp-run-real-handler 2718 ;; No tilde characters in file name, do normal
2719 #'expand-file-name (list localname)))))))) 2719 ;; `expand-file-name' (this does "/./" and "/../").
2720 ;; `default-directory' is bound, because on Windows there
2721 ;; would be problems with UNC shares or Cygwin mounts.
2722 (let ((default-directory (tramp-compat-temporary-file-directory)))
2723 (tramp-make-tramp-file-name
2724 v (tramp-drop-volume-letter
2725 (tramp-run-real-handler
2726 #'expand-file-name (list localname)))))))))
2720 2727
2721;;; Remote commands: 2728;;; Remote commands:
2722 2729
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index ee7e0cf2c3b..75e44551ef9 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -2610,14 +2610,7 @@ Fall back to normal file name handler if no Tramp file name handler exists."
2610 2610
2611 ;; When `tramp-mode' is not enabled, or the file name is quoted, 2611 ;; When `tramp-mode' is not enabled, or the file name is quoted,
2612 ;; we don't do anything. 2612 ;; we don't do anything.
2613 ;; When operation is `expand-file-name', and the first argument 2613 (tramp-run-real-handler operation args))))
2614 ;; is a local absolute file name, we end also here. Handle the
2615 ;; MS Windows case.
2616 (funcall
2617 (if (and (eq operation 'expand-file-name)
2618 (not (string-match-p "\\`[[:alpha:]]:/" (car args))))
2619 #'tramp-drop-volume-letter #'identity)
2620 (tramp-run-real-handler operation args)))))
2621 2614
2622(defun tramp-completion-file-name-handler (operation &rest args) 2615(defun tramp-completion-file-name-handler (operation &rest args)
2623 "Invoke Tramp file name completion handler for OPERATION and ARGS. 2616 "Invoke Tramp file name completion handler for OPERATION and ARGS.