summaryrefslogtreecommitdiff
path: root/lisp/net/tramp-sudoedit.el
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2019-08-12 16:18:59 +0200
committerMichael Albinus <michael.albinus@gmx.de>2019-08-12 16:18:59 +0200
commit88006cf542ed99ca8236c9b61c6b19b732353d6c (patch)
treeb5fb0de0d700d7fa47476fab1be7f79644d9bbd4 /lisp/net/tramp-sudoedit.el
parentf7b5e7d72d1648831fca3fc79cb134eab3407aa1 (diff)
downloademacs-88006cf542ed99ca8236c9b61c6b19b732353d6c.tar.gz
Quote file names properly in Tramp
* lisp/net/tramp.el (tramp-handle-file-truename) (tramp-handle-insert-directory): * lisp/net/tramp-adb.el (tramp-adb-handle-file-truename): * lisp/net/tramp-sh.el (tramp-sh-handle-file-truename) (tramp-sh-handle-insert-directory): * lisp/net/tramp-smb.el (tramp-smb-handle-insert-directory): * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-file-truename): Use `tramp-compat-directory-name-p'. * lisp/net/tramp.el (tramp-drop-volume-letter) (tramp-handle-file-truename): * lisp/net/tramp-adb.el (tramp-adb-handle-file-truename): * lisp/net/tramp-sh.el (tramp-sh-handle-make-symbolic-link) (tramp-sh-handle-file-truename): * lisp/net/tramp-smb.el (tramp-smb-handle-make-symbolic-link): * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-file-truename): (tramp-sudoedit-handle-make-symbolic-link): Quote properly. * lisp/net/tramp-compat.el (tramp-compat-file-name-quote) (tramp-compat-file-name-unquote): Add optional argument TOP.
Diffstat (limited to 'lisp/net/tramp-sudoedit.el')
-rw-r--r--lisp/net/tramp-sudoedit.el57
1 files changed, 29 insertions, 28 deletions
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el
index 5d5a3f1f75c..80ce8f78747 100644
--- a/lisp/net/tramp-sudoedit.el
+++ b/lisp/net/tramp-sudoedit.el
@@ -533,34 +533,36 @@ the result will be a local, non-Tramp, file name."
(defun tramp-sudoedit-handle-file-truename (filename)
"Like `file-truename' for Tramp files."
- ;; Preserve trailing "/".
+ ;; Preserve trailing "/".
(funcall
- (if (string-equal (file-name-nondirectory filename) "")
+ (if (tramp-compat-directory-name-p filename)
#'file-name-as-directory #'identity)
- (with-parsed-tramp-file-name (expand-file-name filename) nil
- (tramp-make-tramp-file-name
- v
- (with-tramp-file-property v localname "file-truename"
- (let ((quoted (tramp-compat-file-name-quoted-p localname))
- (localname (tramp-compat-file-name-unquote localname))
- result)
- (tramp-message v 4 "Finding true name for `%s'" filename)
- (setq result (tramp-sudoedit-send-command-string
- v "readlink" "--canonicalize-missing" localname))
- ;; Detect cycle.
- (when (and (file-symlink-p filename)
- (string-equal result localname))
- (tramp-error
- v 'file-error
- "Apparent cycle of symbolic links for %s" filename))
- ;; If the resulting localname looks remote, we must quote it
- ;; for security reasons.
- (when (or quoted (file-remote-p result))
- (let (file-name-handler-alist)
- (setq result (tramp-compat-file-name-quote result))))
- (tramp-message v 4 "True name of `%s' is `%s'" localname result)
- result))
- 'nohop))))
+ ;; Quote properly.
+ (funcall
+ (if (tramp-compat-file-name-quoted-p filename)
+ #'tramp-compat-file-name-quote #'identity)
+ (with-parsed-tramp-file-name
+ (tramp-compat-file-name-unquote (expand-file-name filename)) nil
+ (tramp-make-tramp-file-name
+ v
+ (with-tramp-file-property v localname "file-truename"
+ (let (result)
+ (tramp-message v 4 "Finding true name for `%s'" filename)
+ (setq result (tramp-sudoedit-send-command-string
+ v "readlink" "--canonicalize-missing" localname))
+ ;; Detect cycle.
+ (when (and (file-symlink-p filename)
+ (string-equal result localname))
+ (tramp-error
+ v 'file-error
+ "Apparent cycle of symbolic links for %s" filename))
+ ;; If the resulting localname looks remote, we must quote it
+ ;; for security reasons.
+ (when (file-remote-p result)
+ (setq result (tramp-compat-file-name-quote result 'top)))
+ (tramp-message v 4 "True name of `%s' is `%s'" localname result)
+ result))
+ 'nohop)))))
(defun tramp-sudoedit-handle-file-writable-p (filename)
"Like `file-writable-p' for Tramp files."
@@ -609,8 +611,7 @@ component is used as the target of the symlink."
;; If TARGET is still remote, quote it.
(if (tramp-tramp-file-p target)
- (make-symbolic-link
- (let (file-name-handler-alist) (tramp-compat-file-name-quote target))
+ (make-symbolic-link (tramp-compat-file-name-quote target 'top)
linkname ok-if-already-exists)
;; Do the 'confirm if exists' thing.