Handle quoted tilde in Tramp
* lisp/net/tramp.el (tramp-handle-expand-file-name): * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-expand-file-name): * lisp/net/tramp-sh.el (tramp-sh-handle-expand-file-name): * lisp/net/tramp-smb.el (tramp-smb-handle-expand-file-name): * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-expand-file-name): Handle quoted tilde. (Bug#65685) * test/lisp/net/tramp-tests.el (tramp-test05-expand-file-name-tilde): New test.
This commit is contained in:
parent
30239759ee
commit
c8ea14e782
6 changed files with 27 additions and 1 deletions
|
@ -1176,10 +1176,13 @@ file names."
|
||||||
(tramp-run-real-handler #'expand-file-name (list name))
|
(tramp-run-real-handler #'expand-file-name (list name))
|
||||||
;; Dissect NAME.
|
;; Dissect NAME.
|
||||||
(with-parsed-tramp-file-name name nil
|
(with-parsed-tramp-file-name name nil
|
||||||
|
;; Tilde expansion shall be possible also for quoted localname.
|
||||||
|
(when (string-prefix-p "~" (file-name-unquote localname))
|
||||||
|
(setq localname (file-name-unquote localname)))
|
||||||
;; If there is a default location, expand tilde.
|
;; If there is a default location, expand tilde.
|
||||||
(when (string-match
|
(when (string-match
|
||||||
(tramp-compat-rx bos "~" (group (* (not "/"))) (group (* nonl)) eos)
|
(tramp-compat-rx bos "~" (group (* (not "/"))) (group (* nonl)) eos)
|
||||||
localname)
|
localname)
|
||||||
(let ((uname (match-string 1 localname))
|
(let ((uname (match-string 1 localname))
|
||||||
(fname (match-string 2 localname))
|
(fname (match-string 2 localname))
|
||||||
hname)
|
hname)
|
||||||
|
|
|
@ -2831,6 +2831,9 @@ the result will be a local, non-Tramp, file name."
|
||||||
(tramp-run-real-handler #'expand-file-name (list name)))
|
(tramp-run-real-handler #'expand-file-name (list name)))
|
||||||
(unless (tramp-run-real-handler #'file-name-absolute-p (list localname))
|
(unless (tramp-run-real-handler #'file-name-absolute-p (list localname))
|
||||||
(setq localname (concat "~/" localname)))
|
(setq localname (concat "~/" localname)))
|
||||||
|
;; Tilde expansion shall be possible also for quoted localname.
|
||||||
|
(when (string-prefix-p "~" (file-name-unquote localname))
|
||||||
|
(setq localname (file-name-unquote localname)))
|
||||||
;; Tilde expansion if necessary. This needs a shell which
|
;; Tilde expansion if necessary. This needs a shell which
|
||||||
;; groks tilde expansion! The function `tramp-find-shell' is
|
;; groks tilde expansion! The function `tramp-find-shell' is
|
||||||
;; supposed to find such a shell on the remote host. Please
|
;; supposed to find such a shell on the remote host. Please
|
||||||
|
|
|
@ -731,6 +731,9 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
|
||||||
(tramp-run-real-handler #'expand-file-name (list name))
|
(tramp-run-real-handler #'expand-file-name (list name))
|
||||||
;; Dissect NAME.
|
;; Dissect NAME.
|
||||||
(with-parsed-tramp-file-name name nil
|
(with-parsed-tramp-file-name name nil
|
||||||
|
;; Tilde expansion shall be possible also for quoted localname.
|
||||||
|
(when (string-prefix-p "~" (file-name-unquote localname))
|
||||||
|
(setq localname (file-name-unquote localname)))
|
||||||
;; Tilde expansion if necessary.
|
;; Tilde expansion if necessary.
|
||||||
(when (string-match
|
(when (string-match
|
||||||
(tramp-compat-rx bos "~" (group (* (not "/"))) (group (* nonl)) eos)
|
(tramp-compat-rx bos "~" (group (* (not "/"))) (group (* nonl)) eos)
|
||||||
|
|
|
@ -380,6 +380,9 @@ the result will be a local, non-Tramp, file name."
|
||||||
;; but to the root home directory.
|
;; but to the root home directory.
|
||||||
(when (tramp-string-empty-or-nil-p localname)
|
(when (tramp-string-empty-or-nil-p localname)
|
||||||
(setq localname "~"))
|
(setq localname "~"))
|
||||||
|
;; Tilde expansion shall be possible also for quoted localname.
|
||||||
|
(when (string-prefix-p "~" (file-name-unquote localname))
|
||||||
|
(setq localname (file-name-unquote localname)))
|
||||||
(unless (file-name-absolute-p localname)
|
(unless (file-name-absolute-p localname)
|
||||||
(setq localname (format "~%s/%s" user localname)))
|
(setq localname (format "~%s/%s" user localname)))
|
||||||
(when (string-match
|
(when (string-match
|
||||||
|
|
|
@ -3982,6 +3982,9 @@ Let-bind it when necessary.")
|
||||||
(with-parsed-tramp-file-name name nil
|
(with-parsed-tramp-file-name name nil
|
||||||
(unless (tramp-run-real-handler #'file-name-absolute-p (list localname))
|
(unless (tramp-run-real-handler #'file-name-absolute-p (list localname))
|
||||||
(setq localname (concat "/" localname)))
|
(setq localname (concat "/" localname)))
|
||||||
|
;; Tilde expansion shall be possible also for quoted localname.
|
||||||
|
(when (string-prefix-p "~" (file-name-unquote localname))
|
||||||
|
(setq localname (file-name-unquote localname)))
|
||||||
;; Expand tilde. Usually, the methods applying this handler do
|
;; Expand tilde. Usually, the methods applying this handler do
|
||||||
;; not support tilde expansion. But users could declare a
|
;; not support tilde expansion. But users could declare a
|
||||||
;; respective connection property. (Bug#53847)
|
;; respective connection property. (Bug#53847)
|
||||||
|
|
|
@ -2335,6 +2335,17 @@ Also see `ignore'."
|
||||||
(should (string-equal (expand-file-name local dir) dir))
|
(should (string-equal (expand-file-name local dir) dir))
|
||||||
(should (string-equal (expand-file-name (concat dir local)) dir)))))
|
(should (string-equal (expand-file-name (concat dir local)) dir)))))
|
||||||
|
|
||||||
|
;; The following test is inspired by Bug#65685.
|
||||||
|
(ert-deftest tramp-test05-expand-file-name-tilde ()
|
||||||
|
"Check `expand-file-name'."
|
||||||
|
(skip-unless (tramp--test-enabled))
|
||||||
|
(skip-unless (not (tramp--test-ange-ftp-p)))
|
||||||
|
|
||||||
|
(let ((dir (file-remote-p ert-remote-temporary-file-directory))
|
||||||
|
(tramp-tolerate-tilde t))
|
||||||
|
(should (string-equal (expand-file-name (concat dir "~"))
|
||||||
|
(expand-file-name (concat dir "/:~"))))))
|
||||||
|
|
||||||
(ert-deftest tramp-test06-directory-file-name ()
|
(ert-deftest tramp-test06-directory-file-name ()
|
||||||
"Check `directory-file-name'.
|
"Check `directory-file-name'.
|
||||||
This checks also `file-name-as-directory', `file-name-directory',
|
This checks also `file-name-as-directory', `file-name-directory',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue