]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp.el
nnimap respool fix
[gnu-emacs] / lisp / net / tramp.el
index 727536b2e10c9f3f52f37dbf4c1de19634fa8c2a..face017946dcb32a1b9b5d682551c0bbfe69e1a8 100644 (file)
@@ -1,6 +1,6 @@
 ;;; tramp.el --- Transparent Remote Access, Multiple Protocol
 
-;; Copyright (C) 1998-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1998-2014 Free Software Foundation, Inc.
 
 ;; Author: Kai Großjohann <kai.grossjohann@gmx.net>
 ;;         Michael Albinus <michael.albinus@gmx.de>
@@ -49,9 +49,8 @@
 ;;            http://lists.gnu.org/mailman/listinfo/tramp-devel
 ;;
 ;; For the adventurous, the current development sources are available
-;; via CVS.  You can find instructions about this at the following URL:
+;; via Git.  You can find instructions about this at the following URL:
 ;;            http://savannah.gnu.org/projects/tramp/
-;; Click on "CVS" in the navigation bar near the top.
 ;;
 ;; Don't forget to put on your asbestos longjohns, first!
 
@@ -66,6 +65,7 @@
 (defvar directory-sep-char)
 (defvar eshell-path-env)
 (defvar file-notify-descriptors)
+(defvar ls-lisp-use-insert-directory-program)
 (defvar outline-regexp)
 
 ;;; User Customizable Internal Variables:
@@ -566,11 +566,15 @@ This regexp must match both `tramp-initial-end-of-output' and
   :type 'regexp)
 
 (defcustom tramp-password-prompt-regexp
-  "^.*\\([pP]assword\\|[pP]assphrase\\).*:\^@? *"
+  (format "^.*\\(%s\\).*:\^@? *"
+         (if (boundp 'password-word-equivalents)
+             (regexp-opt (symbol-value 'password-word-equivalents))
+           "password\\|passphrase"))
   "Regexp matching password-like prompts.
 The regexp should match at end of buffer.
 
 The `sudo' program appears to insert a `^@' character into the prompt."
+  :version "24.4"
   :group 'tramp
   :type 'regexp)
 
@@ -848,7 +852,7 @@ Derived from `tramp-postfix-host-format'.")
    "\\(?:" "\\("   tramp-method-regexp "\\)" tramp-postfix-method-regexp "\\)?"
    "\\(?:" "\\("   tramp-user-regexp   "\\)" tramp-postfix-user-regexp   "\\)?"
    "\\("   "\\(?:" tramp-host-regexp   "\\|"
-                  tramp-prefix-ipv6-regexp  tramp-ipv6-regexp
+                  tramp-prefix-ipv6-regexp  "\\(?:" tramp-ipv6-regexp "\\)?"
                                             tramp-postfix-ipv6-regexp "\\)"
           "\\(?:" tramp-prefix-port-regexp  tramp-port-regexp "\\)?" "\\)?")
 "Regular expression matching a Tramp file name between prefix and postfix.")
@@ -884,8 +888,8 @@ See also `tramp-file-name-regexp'.")
 ;;;###autoload
 (defconst tramp-file-name-regexp-unified
   (if (memq system-type '(cygwin windows-nt))
-      "\\`/\\([^[/|:]\\{2,\\}\\|[^/|]\\{2,\\}]\\):"
-    "\\`/\\([^[/|:]+\\|[^/|]+]\\):")
+      "\\`/\\(\\[.*\\]\\|[^/|:]\\{2,\\}[^/|]*\\):"
+    "\\`/[^/|:][^/|]*:")
   "Value for `tramp-file-name-regexp' for unified remoting.
 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
 Tramp.  See `tramp-file-name-structure' for more explanations.
@@ -1222,10 +1226,11 @@ their replacement."
       ;; This works with the current set of `tramp-obsolete-methods'.
       ;; Must be improved, if their are more sophisticated replacements.
       (setq result (substring result 0 -1)))
-    ;; We must mark, whether a default value has been used.
-    (if (or method (null result))
+    ;; We must mark, whether a default value has been used.  Not
+    ;; applicable for XEmacs.
+    (if (or method (null result) (null (functionp 'propertize)))
        result
-      (propertize result 'tramp-default t))))
+      (tramp-compat-funcall 'propertize result 'tramp-default t))))
 
 (defun tramp-find-user (method user host)
   "Return the right user string to use.
@@ -1243,10 +1248,11 @@ This is USER, if non-nil. Otherwise, do a lookup in
                   (setq choices nil)))
               luser)
             tramp-default-user)))
-    ;; We must mark, whether a default value has been used.
-    (if (or user (null result))
+    ;; We must mark, whether a default value has been used.  Not
+    ;; applicable for XEmacs.
+    (if (or user (null result) (null (functionp 'propertize)))
        result
-      (propertize result 'tramp-default t))))
+      (tramp-compat-funcall 'propertize result 'tramp-default t))))
 
 (defun tramp-find-host (method user host)
   "Return the right host string to use.
@@ -1263,15 +1269,19 @@ This is HOST, if non-nil. Otherwise, it is `tramp-default-host'."
        lhost)
       tramp-default-host))
 
-(defun tramp-check-proper-host (vec)
-  "Check host name of VEC."
+(defun tramp-check-proper-method-and-host (vec)
+  "Check method and host name of VEC."
   (let ((method (tramp-file-name-method vec))
        (user (tramp-file-name-user vec))
-       (host (tramp-file-name-host vec)))
+       (host (tramp-file-name-host vec))
+       (methods (mapcar 'car tramp-methods)))
+    (when (and method (not (member method methods)))
+      (tramp-cleanup-connection vec)
+      (tramp-user-error vec "Unknown method \"%s\"" method))
     (when (and (equal tramp-syntax 'ftp) host
               (or (null method) (get-text-property 0 'tramp-default method))
               (or (null user) (get-text-property 0 'tramp-default user))
-              (member host (mapcar 'car tramp-methods)))
+              (member host methods))
       (tramp-cleanup-connection vec)
       (tramp-user-error vec "Host name must not match method \"%s\"" host))))
 
@@ -1427,67 +1437,65 @@ The outline level is equal to the verbosity of the Tramp message."
   "Append message to debug buffer.
 Message is formatted with FMT-STRING as control string and the remaining
 ARGUMENTS to actually emit the message (if applicable)."
-  (when (get-buffer (tramp-buffer-name vec))
-    (with-current-buffer (tramp-get-debug-buffer vec)
-      (goto-char (point-max))
-      ;; Headline.
-      (when (bobp)
-       (insert
-        (format
-         ";; %sEmacs: %s Tramp: %s -*- mode: outline; -*-"
-         (if (featurep 'sxemacs) "SX" (if (featurep 'xemacs) "X" "GNU "))
-         emacs-version tramp-version)))
-      (unless (bolp)
-       (insert "\n"))
-      ;; Timestamp.
-      (let ((now (current-time)))
-        (insert (format-time-string "%T." now))
-        (insert (format "%06d " (nth 2 now))))
-      ;; Calling Tramp function.  We suppress compat and trace
-      ;; functions from being displayed.
-      (let ((btn 1) btf fn)
-       (while (not fn)
-         (setq btf (nth 1 (backtrace-frame btn)))
-         (if (not btf)
-             (setq fn "")
-           (when (symbolp btf)
-             (setq fn (symbol-name btf))
-             (unless
-                 (and
-                  (string-match "^tramp" fn)
-                  (not
-                   (string-match
-                    (concat
-                     "^"
-                     (regexp-opt
-                      '("tramp-backtrace"
-                        "tramp-compat-condition-case-unless-debug"
-                        "tramp-compat-funcall"
-                        "tramp-compat-with-temp-message"
-                        "tramp-condition-case-unless-debug"
-                        "tramp-debug-message"
-                        "tramp-error"
-                        "tramp-error-with-buffer"
-                        "tramp-message"
-                        "tramp-user-error")
-                      t)
-                     "$")
-                    fn)))
-               (setq fn nil)))
-           (setq btn (1+ btn))))
-       ;; The following code inserts filename and line number.
-       ;; Should be inactive by default, because it is time
-       ;; consuming.
-;      (let ((ffn (find-function-noselect (intern fn))))
-;        (insert
-;         (format
-;          "%s:%d: "
-;          (file-name-nondirectory (buffer-file-name (car ffn)))
-;          (with-current-buffer (car ffn)
-;            (1+ (count-lines (point-min) (cdr ffn)))))))
-       (insert (format "%s " fn)))
-      ;; The message.
-      (insert (apply 'format fmt-string arguments)))))
+  (with-current-buffer (tramp-get-debug-buffer vec)
+    (goto-char (point-max))
+    ;; Headline.
+    (when (bobp)
+      (insert
+       (format
+       ";; %sEmacs: %s Tramp: %s -*- mode: outline; -*-"
+       (if (featurep 'sxemacs) "SX" (if (featurep 'xemacs) "X" "GNU "))
+       emacs-version tramp-version)))
+    (unless (bolp)
+      (insert "\n"))
+    ;; Timestamp.
+    (let ((now (current-time)))
+      (insert (format-time-string "%T." now))
+      (insert (format "%06d " (nth 2 now))))
+    ;; Calling Tramp function.  We suppress compat and trace functions
+    ;; from being displayed.
+    (let ((btn 1) btf fn)
+      (while (not fn)
+       (setq btf (nth 1 (backtrace-frame btn)))
+       (if (not btf)
+           (setq fn "")
+         (when (symbolp btf)
+           (setq fn (symbol-name btf))
+           (unless
+               (and
+                (string-match "^tramp" fn)
+                (not
+                 (string-match
+                  (concat
+                   "^"
+                   (regexp-opt
+                    '("tramp-backtrace"
+                      "tramp-compat-condition-case-unless-debug"
+                      "tramp-compat-funcall"
+                      "tramp-compat-with-temp-message"
+                      "tramp-condition-case-unless-debug"
+                      "tramp-debug-message"
+                      "tramp-error"
+                      "tramp-error-with-buffer"
+                      "tramp-message"
+                      "tramp-user-error")
+                    t)
+                   "$")
+                  fn)))
+             (setq fn nil)))
+         (setq btn (1+ btn))))
+      ;; The following code inserts filename and line number.  Should
+      ;; be inactive by default, because it is time consuming.
+;      (let ((ffn (find-function-noselect (intern fn))))
+;      (insert
+;       (format
+;        "%s:%d: "
+;        (file-name-nondirectory (buffer-file-name (car ffn)))
+;        (with-current-buffer (car ffn)
+;          (1+ (count-lines (point-min) (cdr ffn)))))))
+      (insert (format "%s " fn)))
+    ;; The message.
+    (insert (apply 'format fmt-string arguments))))
 
 (defvar tramp-message-show-message t
   "Show Tramp message in the minibuffer.
@@ -1524,13 +1532,13 @@ applicable)."
                 arguments))
        ;; Log only when there is a minimum level.
        (when (>= tramp-verbose 4)
-         (when (and vec-or-proc
-                    (processp vec-or-proc)
-                    (buffer-name (process-buffer vec-or-proc)))
-           (with-current-buffer (process-buffer vec-or-proc)
-             ;; Translate proc to vec.
-             (setq vec-or-proc (tramp-dissect-file-name default-directory))))
-         (when (and vec-or-proc (vectorp vec-or-proc))
+         ;; Translate proc to vec.
+         (when (processp vec-or-proc)
+           (let ((tramp-verbose 0))
+             (setq vec-or-proc
+                   (tramp-get-connection-property vec-or-proc "vector" nil))))
+         ;; Do it.
+         (when (vectorp vec-or-proc)
            (apply 'tramp-debug-message
                   vec-or-proc
                   (concat (format "(%d) # " level) fmt-string)
@@ -1542,7 +1550,7 @@ If VEC-OR-PROC is nil, the buffer *debug tramp* is used.  This
 function is meant for debugging purposes."
   (if vec-or-proc
       (tramp-message vec-or-proc 10 "\n%s" (with-output-to-string (backtrace)))
-    (if (<= 10 tramp-verbose)
+    (if (>= tramp-verbose 10)
        (with-output-to-temp-buffer "*debug tramp*" (backtrace)))))
 
 (defsubst tramp-error (vec-or-proc signal fmt-string &rest arguments)
@@ -1552,12 +1560,13 @@ signal identifier to be raised, remaining arguments passed to
 `tramp-message'.  Finally, signal SIGNAL is raised."
   (let (tramp-message-show-message)
     (tramp-backtrace vec-or-proc)
-    (tramp-message
-     vec-or-proc 1 "%s"
-     (error-message-string
-      (list signal
-           (get signal 'error-message)
-           (apply 'format fmt-string arguments))))
+    (when vec-or-proc
+      (tramp-message
+       vec-or-proc 1 "%s"
+       (error-message-string
+       (list signal
+             (get signal 'error-message)
+             (apply 'format fmt-string arguments)))))
     (signal signal (list (apply 'format fmt-string arguments)))))
 
 (defsubst tramp-error-with-buffer
@@ -1641,7 +1650,7 @@ without a visible progress reporter."
   (declare (indent 3) (debug t))
   `(progn
      (tramp-message ,vec ,level "%s..." ,message)
-     (let ((result "failed")
+     (let ((cookie "failed")
            (tm
             ;; We start a pulsing progress reporter after 3 seconds.  Feature
             ;; introduced in Emacs 24.1.
@@ -1656,10 +1665,10 @@ without a visible progress reporter."
                                  #'tramp-progress-reporter-update pr)))))))
        (unwind-protect
            ;; Execute the body.
-           (prog1 (progn ,@body) (setq result "done"))
+           (prog1 (progn ,@body) (setq cookie "done"))
          ;; Stop progress reporter.
          (if tm (tramp-compat-funcall 'cancel-timer tm))
-         (tramp-message ,vec ,level "%s...%s" ,message result)))))
+         (tramp-message ,vec ,level "%s...%s" ,message cookie)))))
 
 (tramp-compat-font-lock-add-keywords
  'emacs-lisp-mode '("\\<with-tramp-progress-reporter\\>"))
@@ -1710,19 +1719,6 @@ letter into the file name.  This function removes it."
        (replace-match "/" nil t name)
       name)))
 
-(defun tramp-cleanup (vec)
-  "Cleanup connection VEC, but keep the debug buffer."
-  (with-current-buffer (tramp-get-debug-buffer vec)
-    ;; Keep the debug buffer.
-    (rename-buffer
-     (generate-new-buffer-name tramp-temp-buffer-name) 'unique)
-    (tramp-cleanup-connection vec)
-    (if (= (point-min) (point-max))
-       (kill-buffer nil)
-      (rename-buffer (tramp-debug-buffer-name vec) 'unique))
-    ;; We call `tramp-get-buffer' in order to keep the debug buffer.
-    (tramp-get-buffer vec)))
-
 ;;; Config Manipulation Functions:
 
 ;;;###tramp-autoload
@@ -1828,7 +1824,7 @@ been set up by `rfn-eshadow-setup-minibuffer'."
          ;; We do not want to send any remote command.
          (non-essential t))
       (when
-         (file-remote-p
+         (tramp-tramp-file-p
           (tramp-compat-funcall
            'buffer-substring-no-properties end (point-max)))
        (save-excursion
@@ -2029,8 +2025,8 @@ ARGS are the arguments OPERATION has been called with."
                  'vm-imap-move-mail 'vm-pop-move-mail 'vm-spool-move-mail))
     (save-match-data
       (cond
-       ((string-match tramp-file-name-regexp (nth 0 args)) (nth 0 args))
-       ((string-match tramp-file-name-regexp (nth 1 args)) (nth 1 args))
+       ((tramp-tramp-file-p (nth 0 args)) (nth 0 args))
+       ((tramp-tramp-file-p (nth 1 args)) (nth 1 args))
        (t (buffer-file-name (current-buffer))))))
    ;; START END FILE.
    ((eq operation 'write-region)
@@ -2145,7 +2141,7 @@ Falls back to normal file name handler if no Tramp file name handler exists."
                          (tramp-message
                           v 1 "Suppress received in operation %s"
                           (append (list operation) args))
-                         (tramp-cleanup v)
+                         (tramp-cleanup-connection v t)
                          (tramp-run-real-handler operation args)))
                       (t result)))
 
@@ -2363,7 +2359,8 @@ not in completion mode."
   (and (tramp-tramp-file-p filename)
        (with-parsed-tramp-file-name filename nil
         (or (not (tramp-completion-mode-p))
-            (let ((p (tramp-get-connection-process v)))
+            (let* ((tramp-verbose 0)
+                   (p (tramp-get-connection-process v)))
               (and p (processp p) (memq (process-status p) '(run open))))))))
 
 ;; Method, host name and user name completion.
@@ -2941,7 +2938,8 @@ User is always nil."
 
 (defun tramp-handle-file-remote-p (filename &optional identification connected)
   "Like `file-remote-p' for Tramp files."
-  (let ((tramp-verbose 3))
+  ;; We do not want traces in the debug buffer.
+  (let ((tramp-verbose (min tramp-verbose 3)))
     (when (tramp-tramp-file-p filename)
       (let* ((v (tramp-dissect-file-name filename))
             (p (tramp-get-connection-process v))
@@ -3010,6 +3008,38 @@ User is always nil."
 
       (tramp-run-real-handler 'find-backup-file-name (list filename)))))
 
+(defun tramp-handle-insert-directory
+  (filename switches &optional wildcard full-directory-p)
+  "Like `insert-directory' for Tramp files."
+  (unless switches (setq switches ""))
+  ;; Mark trailing "/".
+  (when (and (zerop (length (file-name-nondirectory filename)))
+            (not full-directory-p))
+    (setq switches (concat switches "F")))
+  (with-parsed-tramp-file-name (expand-file-name filename) nil
+    (with-tramp-progress-reporter v 0 (format "Opening directory %s" filename)
+      (require 'ls-lisp)
+      (let (ls-lisp-use-insert-directory-program start)
+       (tramp-run-real-handler
+        'insert-directory
+        (list filename switches wildcard full-directory-p))
+       ;; `ls-lisp' always returns full listings.  We must remove
+       ;; superfluous parts.
+       (unless (string-match "l" switches)
+         (save-excursion
+           (goto-char (point-min))
+           (while (setq start
+                        (text-property-not-all
+                         (point) (point-at-eol) 'dired-filename t))
+             (delete-region
+              start
+              (or (text-property-any start (point-at-eol) 'dired-filename t)
+                  (point-at-eol)))
+             (if (=  (point-at-bol) (point-at-eol))
+                 ;; Empty line.
+                 (delete-region (point) (progn (forward-line) (point)))
+               (forward-line)))))))))
+
 (defun tramp-handle-insert-file-contents
   (filename &optional visit beg end replace)
   "Like `insert-file-contents' for Tramp files."
@@ -3021,10 +3051,13 @@ User is always nil."
          v 3 (format "Inserting `%s'" filename)
        (unwind-protect
            (if (not (file-exists-p filename))
-               ;; We don't raise a Tramp error, because it might be
-               ;; suppressed, like in `find-file-noselect-1'.
-               (signal 'file-error
-                       (list "File not found on remote host" filename))
+               (progn
+                 ;; We don't raise a Tramp error, because it might be
+                 ;; suppressed, like in `find-file-noselect-1'.
+                 (tramp-message
+                  v 1 "File not `%s' found on remote host" filename)
+                 (signal 'file-error
+                         (list "File not found on remote host" filename)))
 
              (if (and (tramp-local-host-p v)
                       (let (file-name-handler-alist)
@@ -3037,8 +3070,11 @@ User is always nil."
                         (list localname visit beg end replace)))
 
                ;; When we shall insert only a part of the file, we
-               ;; copy this part.
-               (when (or beg end)
+               ;; copy this part.  This works only for the shell file
+               ;; name handlers.
+               (when (and (or beg end)
+                          (tramp-get-method-parameter
+                           (tramp-file-name-method v) 'tramp-login-program))
                  (setq remote-copy (tramp-make-tramp-temp-file v))
                  ;; This is defined in tramp-sh.el.  Let's assume
                  ;; this is loaded already.
@@ -3057,7 +3093,8 @@ User is always nil."
                    (end
                     (format "dd bs=1 count=%d if=%s of=%s"
                             end (tramp-shell-quote-argument localname)
-                            remote-copy)))))
+                            remote-copy))))
+                 (setq tramp-temp-buffer-file-name nil beg nil end nil))
 
                ;; `insert-file-contents-literally' takes care to
                ;; avoid calling jka-compr.  By let-binding
@@ -3100,7 +3137,7 @@ User is always nil."
                        filename local-copy)))
                  (setq result
                        (insert-file-contents
-                        local-copy visit nil nil replace)))))
+                        local-copy visit beg end replace)))))
 
          ;; Save exit.
          (progn
@@ -3144,12 +3181,18 @@ User is always nil."
       (let ((tramp-message-show-message (not nomessage)))
        (with-tramp-progress-reporter v 0 (format "Loading %s" file)
          (let ((local-copy (file-local-copy file)))
-           ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
            (unwind-protect
-               (load local-copy noerror t t)
+               (tramp-compat-load local-copy noerror t nosuffix must-suffix)
              (delete-file local-copy)))))
       t)))
 
+(defun tramp-handle-make-symbolic-link
+  (filename linkname &optional ok-if-already-exists)
+  "Like `make-symbolic-link' for Tramp files."
+  (with-parsed-tramp-file-name
+      (if (tramp-tramp-file-p filename) filename linkname) nil
+    (tramp-error v 'file-error "make-symbolic-link not supported")))
+
 (defun tramp-handle-shell-command
   (command &optional output-buffer error-buffer)
   "Like `shell-command' for Tramp files."
@@ -3252,7 +3295,9 @@ User is always nil."
       ;; "/m:h:~" does not work for completion.  We use "/m:h:~/".
       (when (string-match "~$" filename)
        (setq filename (concat filename "/"))))
-    (tramp-run-real-handler 'substitute-in-file-name (list filename))))
+    ;; We do not want to replace environment variables, again.
+    (let (process-environment)
+      (tramp-run-real-handler 'substitute-in-file-name (list filename)))))
 
 (defun tramp-handle-unhandled-file-name-directory (_filename)
   "Like `unhandled-file-name-directory' for Tramp files."
@@ -3354,7 +3399,14 @@ of."
 (defun tramp-action-password (proc vec)
   "Query the user for a password."
   (with-current-buffer (process-buffer proc)
-    (let ((enable-recursive-minibuffers t))
+    (let ((enable-recursive-minibuffers t)
+         (case-fold-search t))
+      ;; Let's check whether a wrong password has been sent already.
+      ;; Sometimes, the process returns a new password request
+      ;; immediately after rejecting the previous (wrong) one.
+      (goto-char (point-min))
+      (when (search-forward-regexp tramp-wrong-passwd-regexp nil t)
+       (tramp-clear-passwd vec))
       (tramp-check-for-regexp proc tramp-password-prompt-regexp)
       (tramp-message vec 3 "Sending %s" (match-string 1))
       ;; We don't call `tramp-send-string' in order to hide the
@@ -3440,7 +3492,8 @@ The terminal type can be configured with `tramp-terminal-type'."
 
 (defun tramp-process-one-action (proc vec actions)
   "Wait for output from the shell and perform one action."
-  (let (found todo item pattern action)
+  (let ((case-fold-search t)
+       found todo item pattern action)
     (while (not found)
       ;; Reread output once all actions have been performed.
       ;; Obviously, the output was not complete.
@@ -3462,8 +3515,8 @@ The terminal type can be configured with `tramp-terminal-type'."
 PROC and VEC indicate the remote connection to be used.  POS, if
 set, is the starting point of the region to be deleted in the
 connection buffer."
-  ;; Enable `auth-source' and `password-cache'.  We must use
-  ;; tramp-current-* variables in case we have several hops.
+  ;; Enable `auth-source'.  We must use tramp-current-* variables in
+  ;; case we have several hops.
   (tramp-set-connection-property
    (tramp-dissect-file-name
     (tramp-make-tramp-file-name
@@ -3666,8 +3719,8 @@ Example:
 would yield `t'.  On the other hand, the following check results in nil:
 
   (tramp-equal-remote \"/sudo::/etc\" \"/su::/etc\")"
-  (and (stringp (file-remote-p file1))
-       (stringp (file-remote-p file2))
+  (and (tramp-tramp-file-p file1)
+       (tramp-tramp-file-p file2)
        (string-equal (file-remote-p file1) (file-remote-p file2))))
 
 ;;;###tramp-autoload
@@ -3815,9 +3868,17 @@ be granted."
        (or
         result
         (let ((file-attr
-               (tramp-get-file-property
-                vec (tramp-file-name-localname vec)
-                (concat "file-attributes-" suffix) nil))
+              (or
+               (tramp-get-file-property
+                vec (tramp-file-name-localname vec)
+                (concat "file-attributes-" suffix) nil)
+               (file-attributes
+                (tramp-make-tramp-file-name
+                 (tramp-file-name-method vec)
+                 (tramp-file-name-user vec)
+                 (tramp-file-name-host vec)
+                 (tramp-file-name-localname vec))
+                (intern suffix))))
               (remote-uid
                (tramp-get-connection-property
                 vec (concat "uid-" suffix) nil))
@@ -3853,7 +3914,7 @@ be granted."
      (stringp host)
      (string-match tramp-local-host-regexp host)
      ;; The method shall be applied to one of the shell file name
-     ;; handler.  `tramp-local-host-p' is also called for "smb" and
+     ;; handlers.  `tramp-local-host-p' is also called for "smb" and
      ;; alike, where it must fail.
      (tramp-get-method-parameter
       (tramp-file-name-method vec) 'tramp-login-program)
@@ -3920,6 +3981,48 @@ Return the local name of the temporary file."
 
 ;;; Auto saving to a special directory:
 
+(defun tramp-handle-make-auto-save-file-name ()
+  "Like `make-auto-save-file-name' for Tramp files.
+Returns a file name in `tramp-auto-save-directory' for autosaving this file."
+  (let ((tramp-auto-save-directory tramp-auto-save-directory)
+       (buffer-file-name
+        (tramp-subst-strs-in-string
+         '(("_" . "|")
+           ("/" . "_a")
+           (":" . "_b")
+           ("|" . "__")
+           ("[" . "_l")
+           ("]" . "_r"))
+         (buffer-file-name))))
+    ;; File name must be unique.  This is ensured with Emacs 22 (see
+    ;; UNIQUIFY element of `auto-save-file-name-transforms'); but for
+    ;; all other cases we must do it ourselves.
+    (when (boundp 'auto-save-file-name-transforms)
+      (mapc
+       (lambda (x)
+        (when (and (string-match (car x) buffer-file-name)
+                   (not (car (cddr x))))
+          (setq tramp-auto-save-directory
+                (or tramp-auto-save-directory
+                    (tramp-compat-temporary-file-directory)))))
+       (symbol-value 'auto-save-file-name-transforms)))
+    ;; Create directory.
+    (when tramp-auto-save-directory
+      (setq buffer-file-name
+           (expand-file-name buffer-file-name tramp-auto-save-directory))
+      (unless (file-exists-p tramp-auto-save-directory)
+       (make-directory tramp-auto-save-directory t)))
+    ;; Run plain `make-auto-save-file-name'.  There might be an advice when
+    ;; it is not a magic file name operation (since Emacs 22).
+    ;; We must deactivate it temporarily.
+    (if (not (ad-is-active 'make-auto-save-file-name))
+       (tramp-run-real-handler 'make-auto-save-file-name nil)
+      ;; else
+      (ad-deactivate 'make-auto-save-file-name)
+      (prog1
+       (tramp-run-real-handler 'make-auto-save-file-name nil)
+       (ad-activate 'make-auto-save-file-name)))))
+
 (unless (tramp-exists-file-name-handler 'make-auto-save-file-name)
   (defadvice make-auto-save-file-name
     (around tramp-advice-make-auto-save-file-name () activate)
@@ -3989,7 +4092,7 @@ Lisp error raised when PROGRAM is nil is trapped also, returning 1.
 Furthermore, traces are written with verbosity of 6."
   (tramp-message
    (vector tramp-current-method tramp-current-user tramp-current-host nil nil)
-   6 "%s %s %s" program infile args)
+   6 "`%s %s' %s" program (mapconcat 'identity args " ") infile)
   (if (executable-find program)
       (apply 'call-process program infile destination display args)
     1))
@@ -3999,7 +4102,8 @@ Furthermore, traces are written with verbosity of 6."
   "Read a password from user (compat function).
 Consults the auth-source package.
 Invokes `password-read' if available, `read-passwd' else."
-  (let* ((key (tramp-make-tramp-file-name
+  (let* ((case-fold-search t)
+        (key (tramp-make-tramp-file-name
               tramp-current-method tramp-current-user
               tramp-current-host ""))
         (pw-prompt
@@ -4034,9 +4138,6 @@ Invokes `password-read' if available, `read-passwd' else."
                    "password" tramp-current-host tramp-current-method)))
           ;; Try the password cache.
           (when (functionp 'password-read)
-            (unless (tramp-get-connection-property
-                     v "first-password-request" nil)
-              (tramp-compat-funcall 'password-cache-remove key))
             (let ((password
                    (tramp-compat-funcall 'password-read pw-prompt key)))
               (tramp-compat-funcall 'password-cache-add key password)
@@ -4159,7 +4260,7 @@ Only works for Bourne-like shells."
 (defun tramp-eshell-directory-change ()
   "Set `eshell-path-env' to $PATH of the host related to `default-directory'."
   (setq eshell-path-env
-       (if (file-remote-p default-directory)
+       (if (tramp-tramp-file-p default-directory)
            (with-parsed-tramp-file-name default-directory nil
              (mapconcat
               'identity
@@ -4219,11 +4320,6 @@ Only works for Bourne-like shells."
 ;;   tramp-server-local-variable-alist) to define any such variables
 ;;   that they need to, which would then be let bound as appropriate
 ;;   in tramp functions.  (Jason Rumney)
-;; * IMHO, it's a drawback that currently Tramp doesn't support
-;;   Unicode in Dired file names by default.  Is it possible to
-;;   improve Tramp to set LC_ALL to "C" only for commands where Tramp
-;;   expects English?  Or just to set LC_MESSAGES to "C" if Tramp
-;;   expects only English messages?  (Juri Linkov)
 ;; * Make shadowfile.el grok Tramp filenames.  (Bug#4526, Bug#4846)
 ;; * I was wondering if it would be possible to use tramp even if I'm
 ;;   actually using sshfs.  But when I launch a command I would like