From 0e574ea35ea75fa91a38718966ffe6c17b8e93d8 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sun, 6 Dec 2015 18:55:50 +0100 Subject: [PATCH] Fix minor Tramp problems found on BSD * lisp/net/tramp-sh.el (tramp-perl-file-truename): Do not append trailing slash. Quote apostrophes. (tramp-sh-handle-file-truename): Do not append trailing slash in the "ls" case. (tramp-get-ls-command-with-w-option): New defun. (tramp-do-file-attributes-with-ls) (tramp-do-directory-files-and-attributes-with-stat): Use it. * test/automated/tramp-tests.el (tramp-test31-special-characters-with-perl) (tramp-test31-special-characters-with-ls) (tramp-test32-utf8-with-perl, tramp-test32-utf8-with-ls): Suppress also readlink. --- lisp/net/tramp-sh.el | 64 ++++++++++++++++++++--------------- test/automated/tramp-tests.el | 20 ++++++++--- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index a2153415f4d..2c2179e8285 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -621,10 +621,7 @@ if (!$result) { $result = File::Spec->catpath($vol, File::Spec->catdir(@dirs), \"\"); } -if ($ARGV[0] =~ /\\/$/) { - $result = $result . \"/\"; -} - +$result =~ s/\"/\\\\\"/g; print \"\\\"$result\\\"\\n\"; ' \"$1\" 2>/dev/null" "Perl script to produce output suitable for use with `file-truename' @@ -1143,20 +1140,17 @@ target of the symlink differ." ;; Do it yourself. We bind `directory-sep-char' here for ;; XEmacs on Windows, which would otherwise use backslash. - (t (let* ((directory-sep-char ?/) - (steps (tramp-compat-split-string localname "/")) - (localnamedir (tramp-run-real-handler - 'file-name-as-directory (list localname))) - (is-dir (string= localname localnamedir)) - (thisstep nil) - (numchase 0) - ;; Don't make the following value larger than - ;; necessary. People expect an error message in - ;; a timely fashion when something is wrong; - ;; otherwise they might think that Emacs is hung. - ;; Of course, correctness has to come first. - (numchase-limit 20) - symlink-target) + (t (let ((directory-sep-char ?/) + (steps (tramp-compat-split-string localname "/")) + (thisstep nil) + (numchase 0) + ;; Don't make the following value larger than + ;; necessary. People expect an error message in a + ;; timely fashion when something is wrong; + ;; otherwise they might think that Emacs is hung. + ;; Of course, correctness has to come first. + (numchase-limit 20) + symlink-target) (while (and steps (< numchase numchase-limit)) (setq thisstep (pop steps)) (tramp-message @@ -1212,10 +1206,8 @@ target of the symlink differ." (if result (mapconcat 'identity (cons "" result) "/") "/")) - (when (and is-dir - (or (string= "" result) - (not (string= (substring result -1) "/")))) - (setq result (concat result "/")))))) + (when (string= "" result) + (setq result "/"))))) (tramp-message v 4 "True name of `%s' is `%s'" localname result) result)))) @@ -1278,8 +1270,12 @@ target of the symlink differ." (tramp-get-ls-command vec) ;; On systems which have no quoting style, file names ;; with special characters could fail. - (if (tramp-get-ls-command-with-quoting-style vec) - "--quoting-style=c" "") + (cond + ((tramp-get-ls-command-with-quoting-style vec) + "--quoting-style=c") + ((tramp-get-ls-command-with-w-option vec) + "-w") + (t "")) (if (eq id-format 'integer) "-ildn" "-ild") (tramp-shell-quote-argument localname))) ;; Parse `ls -l' output ... @@ -1837,10 +1833,14 @@ be non-negative integers." "-- 2>/dev/null | sed -e 's/\"/\\\\\"/g' -e 's/%s/\"/g'); echo \")\"") (tramp-shell-quote-argument localname) (tramp-get-ls-command vec) - ;; On systems which have no quoting style, file names with - ;; special characters could fail. - (if (tramp-get-ls-command-with-quoting-style vec) - "--quoting-style=shell" "") + ;; On systems which have no quoting style, file names with special + ;; characters could fail. + (cond + ((tramp-get-ls-command-with-quoting-style vec) + "--quoting-style=shell") + ((tramp-get-ls-command-with-w-option vec) + "-w") + (t "")) (tramp-get-remote-stat vec) tramp-stat-marker tramp-stat-marker tramp-stat-marker tramp-stat-marker @@ -5417,6 +5417,14 @@ Return ATTR." vec (format "%s --quoting-style=shell -al /dev/null" (tramp-get-ls-command vec)))))) +(defun tramp-get-ls-command-with-w-option (vec) + (save-match-data + (with-tramp-connection-property vec "ls-w-option" + (tramp-message vec 5 "Checking, whether `ls -w' works") + ;; Option "-w" is available on BSD systems. + (tramp-send-command-and-check + vec (format "%s -alw /dev/null" (tramp-get-ls-command vec)))))) + (defun tramp-get-test-command (vec) (with-tramp-connection-property vec "test" (tramp-message vec 5 "Finding a suitable `test' command") diff --git a/test/automated/tramp-tests.el b/test/automated/tramp-tests.el index c5cab7d5991..8a1743cd200 100644 --- a/test/automated/tramp-tests.el +++ b/test/automated/tramp-tests.el @@ -1987,7 +1987,10 @@ Use the `perl' command." (let ((tramp-connection-properties (append `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory)) - "stat" nil)) + "stat" nil) + ;; See `tramp-sh-handle-file-truename'. + (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory)) + "readlink" nil)) tramp-connection-properties))) (tramp--test-special-characters))) @@ -2005,7 +2008,10 @@ Use the `ls' command." `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory)) "perl" nil) (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory)) - "stat" nil)) + "stat" nil) + ;; See `tramp-sh-handle-file-truename'. + (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory)) + "readlink" nil)) tramp-connection-properties))) (tramp--test-special-characters))) @@ -2059,7 +2065,10 @@ Use the `perl' command." (let ((tramp-connection-properties (append `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory)) - "stat" nil)) + "stat" nil) + ;; See `tramp-sh-handle-file-truename'. + (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory)) + "readlink" nil)) tramp-connection-properties))) (tramp--test-utf8))) @@ -2077,7 +2086,10 @@ Use the `ls' command." `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory)) "perl" nil) (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory)) - "stat" nil)) + "stat" nil) + ;; See `tramp-sh-handle-file-truename'. + (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory)) + "readlink" nil)) tramp-connection-properties))) (tramp--test-utf8))) -- 2.39.2