aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2018-03-26 14:33:24 +0200
committerMichael Albinus2018-03-26 14:33:24 +0200
commitf5834c9ba06529bcd0a6da464f0a808e1be53c5c (patch)
tree3dcd1bdb720012cacaa96e20896630b1343e10a0
parent9c1176247b107fd6e1845618b78ad56b5d57ddd9 (diff)
downloademacs-f5834c9ba06529bcd0a6da464f0a808e1be53c5c.tar.gz
emacs-f5834c9ba06529bcd0a6da464f0a808e1be53c5c.zip
Fix problem with trailing slash in Tramp
* lisp/net/tramp.el (tramp-handle-file-truename): * lisp/net/tramp-adb.el (tramp-adb-handle-file-truename): * lisp/net/tramp-sh.el (tramp-sh-handle-file-truename): Fix problem with trailing slash. * test/lisp/net/tramp-tests.el (tramp-test21-file-links): Test also quoted directories.
-rw-r--r--lisp/net/tramp-adb.el25
-rw-r--r--lisp/net/tramp-sh.el11
-rw-r--r--lisp/net/tramp.el28
-rw-r--r--test/lisp/net/tramp-tests.el16
4 files changed, 45 insertions, 35 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 7a0ea71aee9..fbf6196ca46 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -278,13 +278,16 @@ pass to the OPERATION."
278;; code could be shared? 278;; code could be shared?
279(defun tramp-adb-handle-file-truename (filename) 279(defun tramp-adb-handle-file-truename (filename)
280 "Like `file-truename' for Tramp files." 280 "Like `file-truename' for Tramp files."
281 (format 281 ;; Preserve trailing "/".
282 "%s%s" 282 (funcall
283 (if (string-equal (file-name-nondirectory filename) "")
284 'file-name-as-directory 'identity)
283 (with-parsed-tramp-file-name (expand-file-name filename) nil 285 (with-parsed-tramp-file-name (expand-file-name filename) nil
284 (tramp-make-tramp-file-name 286 (tramp-make-tramp-file-name
285 v 287 v
286 (with-tramp-file-property v localname "file-truename" 288 (with-tramp-file-property v localname "file-truename"
287 (let ((result nil)) ; result steps in reverse order 289 (let ((result nil) ; result steps in reverse order
290 (quoted (tramp-compat-file-name-quoted-p localname)))
288 (tramp-message v 4 "Finding true name for `%s'" filename) 291 (tramp-message v 4 "Finding true name for `%s'" filename)
289 (let* ((steps (split-string localname "/" 'omit)) 292 (let* ((steps (split-string localname "/" 'omit))
290 (localnamedir (tramp-run-real-handler 293 (localnamedir (tramp-run-real-handler
@@ -354,11 +357,19 @@ pass to the OPERATION."
354 (not (string= (substring result -1) "/")))) 357 (not (string= (substring result -1) "/"))))
355 (setq result (concat result "/")))) 358 (setq result (concat result "/"))))
356 359
360 ;; Detect cycle.
361 (when (and (file-symlink-p filename)
362 (string-equal result localname))
363 (tramp-error
364 v 'file-error
365 "Apparent cycle of symbolic links for %s" filename))
366 ;; If the resulting localname looks remote, we must quote it
367 ;; for security reasons.
368 (when (or quoted (file-remote-p result))
369 (let (file-name-handler-alist)
370 (setq result (tramp-compat-file-name-quote result))))
357 (tramp-message v 4 "True name of `%s' is `%s'" localname result) 371 (tramp-message v 4 "True name of `%s' is `%s'" localname result)
358 result)))) 372 result))))))
359
360 ;; Preserve trailing "/".
361 (if (string-equal (file-name-nondirectory filename) "") "/" "")))
362 373
363(defun tramp-adb-handle-file-attributes (filename &optional id-format) 374(defun tramp-adb-handle-file-attributes (filename &optional id-format)
364 "Like `file-attributes' for Tramp files." 375 "Like `file-attributes' for Tramp files."
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 4d7359a4c9c..4cdc39e0b6a 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1128,8 +1128,10 @@ component is used as the target of the symlink."
1128 1128
1129(defun tramp-sh-handle-file-truename (filename) 1129(defun tramp-sh-handle-file-truename (filename)
1130 "Like `file-truename' for Tramp files." 1130 "Like `file-truename' for Tramp files."
1131 (format 1131 ;; Preserve trailing "/".
1132 "%s%s" 1132 (funcall
1133 (if (string-equal (file-name-nondirectory filename) "")
1134 'file-name-as-directory 'identity)
1133 (with-parsed-tramp-file-name (expand-file-name filename) nil 1135 (with-parsed-tramp-file-name (expand-file-name filename) nil
1134 (tramp-make-tramp-file-name 1136 (tramp-make-tramp-file-name
1135 method user domain host port 1137 method user domain host port
@@ -1233,10 +1235,7 @@ component is used as the target of the symlink."
1233 (let (file-name-handler-alist) 1235 (let (file-name-handler-alist)
1234 (setq result (tramp-compat-file-name-quote result)))) 1236 (setq result (tramp-compat-file-name-quote result))))
1235 (tramp-message v 4 "True name of `%s' is `%s'" localname result) 1237 (tramp-message v 4 "True name of `%s' is `%s'" localname result)
1236 result)))) 1238 result))))))
1237
1238 ;; Preserve trailing "/".
1239 (if (string-equal (file-name-nondirectory filename) "") "/" "")))
1240 1239
1241;; Basic functions. 1240;; Basic functions.
1242 1241
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 255c58e48f5..4497802d770 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3208,17 +3208,18 @@ User is always nil."
3208 3208
3209(defun tramp-handle-file-truename (filename) 3209(defun tramp-handle-file-truename (filename)
3210 "Like `file-truename' for Tramp files." 3210 "Like `file-truename' for Tramp files."
3211 (let ((result (expand-file-name filename)) 3211 ;; Preserve trailing "/".
3212 (numchase 0) 3212 (funcall
3213 ;; Don't make the following value larger than 3213 (if (string-equal (file-name-nondirectory filename) "")
3214 ;; necessary. People expect an error message in a 3214 'file-name-as-directory 'identity)
3215 ;; timely fashion when something is wrong; 3215 (let ((result (expand-file-name filename))
3216 ;; otherwise they might think that Emacs is hung. 3216 (numchase 0)
3217 ;; Of course, correctness has to come first. 3217 ;; Don't make the following value larger than necessary.
3218 (numchase-limit 20) 3218 ;; People expect an error message in a timely fashion when
3219 symlink-target) 3219 ;; something is wrong; otherwise they might think that Emacs
3220 (format 3220 ;; is hung. Of course, correctness has to come first.
3221 "%s%s" 3221 (numchase-limit 20)
3222 symlink-target)
3222 (with-parsed-tramp-file-name result v1 3223 (with-parsed-tramp-file-name result v1
3223 (with-tramp-file-property v1 v1-localname "file-truename" 3224 (with-tramp-file-property v1 v1-localname "file-truename"
3224 (while (and (setq symlink-target (file-symlink-p result)) 3225 (while (and (setq symlink-target (file-symlink-p result))
@@ -3243,10 +3244,7 @@ User is always nil."
3243 (tramp-error 3244 (tramp-error
3244 v1 'file-error 3245 v1 'file-error
3245 "Maximum number (%d) of symlinks exceeded" numchase-limit))) 3246 "Maximum number (%d) of symlinks exceeded" numchase-limit)))
3246 (directory-file-name result))) 3247 (directory-file-name result))))))
3247
3248 ;; Preserve trailing "/".
3249 (if (string-equal (file-name-nondirectory filename) "") "/" ""))))
3250 3248
3251(defun tramp-handle-find-backup-file-name (filename) 3249(defun tramp-handle-find-backup-file-name (filename)
3252 "Like `find-backup-file-name' for Tramp files." 3250 "Like `find-backup-file-name' for Tramp files."
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 8e21f5220fc..5851840d009 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -3117,13 +3117,15 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
3117 (delete-file tmp-name1) 3117 (delete-file tmp-name1)
3118 (delete-file tmp-name2))) 3118 (delete-file tmp-name2)))
3119 3119
3120 ;; `file-truename' shall preserve trailing link of directories. 3120 ;; `file-truename' shall preserve trailing slash of directories.
3121 (unless (file-symlink-p tramp-test-temporary-file-directory) 3121 (let* ((dir1
3122 (let* ((dir1 (directory-file-name tramp-test-temporary-file-directory)) 3122 (directory-file-name
3123 (dir2 (file-name-as-directory dir1))) 3123 (funcall
3124 (should (string-equal (file-truename dir1) (expand-file-name dir1))) 3124 (if quoted 'tramp-compat-file-name-quote 'identity)
3125 (should 3125 tramp-test-temporary-file-directory)))
3126 (string-equal (file-truename dir2) (expand-file-name dir2)))))))) 3126 (dir2 (file-name-as-directory dir1)))
3127 (should (string-equal (file-truename dir1) (expand-file-name dir1)))
3128 (should (string-equal (file-truename dir2) (expand-file-name dir2)))))))
3127 3129
3128(ert-deftest tramp-test22-file-times () 3130(ert-deftest tramp-test22-file-times ()
3129 "Check `set-file-times' and `file-newer-than-file-p'." 3131 "Check `set-file-times' and `file-newer-than-file-p'."