]> git.eshelyaron.com Git - emacs.git/commitdiff
* net/tramp.el (tramp-cleanup): Remove. Functionality added to
authorMichael Albinus <michael.albinus@gmx.de>
Tue, 10 Sep 2013 07:45:33 +0000 (09:45 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Tue, 10 Sep 2013 07:45:33 +0000 (09:45 +0200)
`tramp-cleanup-connection'.

* net/tramp-cmds.el (tramp-cleanup-connection): Add optional
parameters KEEP-DEBUG and KEEP-PASSWORD.

* net/tramp.el (tramp-file-name-handler):
* net/tramp-adb.el (tramp-adb-maybe-open-connection):
* net/tramp-sh.el (tramp-open-connection-setup-interactive-shell)
(tramp-maybe-open-connection):
* net/tramp-smb.el (tramp-smb-maybe-open-connection): Use
`tramp-cleanup-connection'.

* net/tramp-sh.el (tramp-maybe-open-connection): Catch
'uname-changed inside the progress reporter.

lisp/ChangeLog
lisp/net/tramp-adb.el
lisp/net/tramp-cmds.el
lisp/net/tramp-sh.el
lisp/net/tramp-smb.el
lisp/net/tramp.el

index c3f6e8860d92537127bc78b56d78c95f2219983b..fc73e5638839722d93254590804297da9e0da7bc 100644 (file)
@@ -1,3 +1,21 @@
+2013-09-10  Michael Albinus  <michael.albinus@gmx.de>
+
+       * net/tramp.el (tramp-cleanup): Remove.  Functionality added to
+       `tramp-cleanup-connection'.
+
+       * net/tramp-cmds.el (tramp-cleanup-connection): Add optional
+       parameters KEEP-DEBUG and KEEP-PASSWORD.
+
+       * net/tramp.el (tramp-file-name-handler):
+       * net/tramp-adb.el (tramp-adb-maybe-open-connection):
+       * net/tramp-sh.el (tramp-open-connection-setup-interactive-shell)
+       (tramp-maybe-open-connection):
+       * net/tramp-smb.el (tramp-smb-maybe-open-connection): Use
+       `tramp-cleanup-connection'.
+
+       * net/tramp-sh.el (tramp-maybe-open-connection): Catch
+       'uname-changed inside the progress reporter.
+
 2013-09-10  Glenn Morris  <rgm@gnu.org>
 
        * simple.el (read-minibuffer): Unbreak it.  (Bug#15318)
index 66d29cb3c8c53b7f59c540958f950999d9d5dea7..595037ab94392cfcbf0045f17bcd38f98aa057b2 100644 (file)
@@ -1153,11 +1153,11 @@ connection if a previous connection has died for some reason."
                      (read (current-buffer))))))
              (when (and (stringp old-getprop)
                         (not (string-equal old-getprop new-getprop)))
-               (tramp-cleanup vec)
                (tramp-message
                 vec 3
                 "Connection reset, because remote host changed from `%s' to `%s'"
                 old-getprop new-getprop)
+               (tramp-cleanup-connection vec t)
                (tramp-adb-maybe-open-connection vec)))
 
            ;; Change user if indicated.
index de06cd5cbc911159604c9da9e41f0d1781578ee9..5015929534dec5bfa62d8be715cfa612238790f0 100644 (file)
     (buffer-list))))
 
 ;;;###tramp-autoload
-(defun tramp-cleanup-connection (vec)
+(defun tramp-cleanup-connection (vec &optional keep-debug keep-password)
   "Flush all connection related objects.
-This includes password cache, file cache, connection cache, buffers.
+This includes password cache, file cache, connection cache,
+buffers.  KEEP-DEBUG non-nil preserves the debug buffer.
+KEEP-PASSWORD non-nil preserves the password cache.
 When called interactively, a Tramp connection has to be selected."
   (interactive
    ;; When interactive, select the Tramp remote identification.
@@ -80,14 +82,15 @@ When called interactively, a Tramp connection has to be selected."
               "Enter Tramp connection: " connections nil t
               (try-completion "" connections)))
        (when (and name (file-remote-p name))
-         (with-parsed-tramp-file-name name nil v))))))
+         (with-parsed-tramp-file-name name nil v))))
+    nil nil))
 
   (if (not vec)
       ;; Nothing to do.
       (message "No Tramp connection found.")
 
     ;; Flush password cache.
-    (tramp-clear-passwd vec)
+    (unless keep-password (tramp-clear-passwd vec))
 
     ;; Flush file cache.
     (tramp-flush-directory-property vec "")
@@ -101,7 +104,8 @@ When called interactively, a Tramp connection has to be selected."
     ;; Remove buffers.
     (dolist
        (buf (list (get-buffer (tramp-buffer-name vec))
-                  (get-buffer (tramp-debug-buffer-name vec))
+                  (unless keep-debug
+                    (get-buffer (tramp-debug-buffer-name vec)))
                   (tramp-get-connection-property vec "process-buffer" nil)))
       (when (bufferp buf) (kill-buffer buf)))))
 
index 2b7c43a49956fc62d63522ebb526bd562a9333df..f91cbb29a1d1473071ead523d83e656faf81258c 100644 (file)
@@ -3805,11 +3805,12 @@ process to set up.  VEC specifies the connection."
          vec "uname"
          (tramp-send-command-and-read vec "echo \\\"`uname -sr`\\\""))))
     (when (and (stringp old-uname) (not (string-equal old-uname new-uname)))
-      (tramp-cleanup vec)
       (tramp-message
        vec 3
        "Connection reset, because remote host changed from `%s' to `%s'"
        old-uname new-uname)
+      ;; We want to keep the password.
+      (tramp-cleanup-connection vec t t)
       (throw 'uname-changed (tramp-maybe-open-connection vec))))
 
   ;; Check whether the remote host suffers from buggy
@@ -4287,68 +4288,68 @@ Does not do anything if a connection is already open, but re-opens the
 connection if a previous connection has died for some reason."
   (tramp-check-proper-host vec)
 
-  (catch 'uname-changed
-    (let ((p (tramp-get-connection-process vec))
-         (process-name (tramp-get-connection-property vec "process-name" nil))
-         (process-environment (copy-sequence process-environment))
-         (pos (with-current-buffer (tramp-get-connection-buffer vec) (point))))
-
-      ;; If Tramp opens the same connection within a short time frame,
-      ;; there is a problem.  We shall signal this.
-      (unless (or (and p (processp p) (memq (process-status p) '(run open)))
-                 (not (equal (butlast (append vec nil) 2)
-                             (car tramp-current-connection)))
-                 (> (tramp-time-diff
-                     (current-time) (cdr tramp-current-connection))
-                    (or tramp-connection-min-time-diff 0)))
-       (throw 'suppress 'suppress))
-
-      ;; If too much time has passed since last command was sent, look
-      ;; whether process is still alive.  If it isn't, kill it.  When
-      ;; using ssh, it can sometimes happen that the remote end has
-      ;; hung up but the local ssh client doesn't recognize this until
-      ;; it tries to send some data to the remote end.  So that's why
-      ;; we try to send a command from time to time, then look again
-      ;; whether the process is really alive.
-      (condition-case nil
-         (when (and (> (tramp-time-diff
-                        (current-time)
-                        (tramp-get-connection-property
-                         p "last-cmd-time" '(0 0 0)))
-                       60)
-                    p (processp p) (memq (process-status p) '(run open)))
-           (tramp-send-command vec "echo are you awake" t t)
-           (unless (and (memq (process-status p) '(run open))
-                        (tramp-wait-for-output p 10))
-             ;; The error will be caught locally.
-             (tramp-error vec 'file-error "Awake did fail")))
-       (file-error
-        (tramp-cleanup vec)
-        (setq p nil)))
-
-      ;; New connection must be opened.
-      (condition-case err
-         (unless (and p (processp p) (memq (process-status p) '(run open)))
-
-           ;; We call `tramp-get-buffer' in order to get a debug
-           ;; buffer for messages from the beginning.
-           (tramp-get-buffer vec)
-
-           ;; If `non-essential' is non-nil, don't reopen a new connection.
-           (when (and (boundp 'non-essential) (symbol-value 'non-essential))
-             (throw 'non-essential 'non-essential))
-
-           (with-tramp-progress-reporter
-               vec 3
-               (if (zerop (length (tramp-file-name-user vec)))
-                   (format "Opening connection for %s using %s"
-                           (tramp-file-name-host vec)
-                           (tramp-file-name-method vec))
-                 (format "Opening connection for %s@%s using %s"
-                         (tramp-file-name-user vec)
+  (let ((p (tramp-get-connection-process vec))
+       (process-name (tramp-get-connection-property vec "process-name" nil))
+       (process-environment (copy-sequence process-environment))
+       (pos (with-current-buffer (tramp-get-connection-buffer vec) (point))))
+
+    ;; If Tramp opens the same connection within a short time frame,
+    ;; there is a problem.  We shall signal this.
+    (unless (or (and p (processp p) (memq (process-status p) '(run open)))
+               (not (equal (butlast (append vec nil) 2)
+                           (car tramp-current-connection)))
+               (> (tramp-time-diff
+                   (current-time) (cdr tramp-current-connection))
+                  (or tramp-connection-min-time-diff 0)))
+      (throw 'suppress 'suppress))
+
+    ;; If too much time has passed since last command was sent, look
+    ;; whether process is still alive.  If it isn't, kill it.  When
+    ;; using ssh, it can sometimes happen that the remote end has hung
+    ;; up but the local ssh client doesn't recognize this until it
+    ;; tries to send some data to the remote end.  So that's why we
+    ;; try to send a command from time to time, then look again
+    ;; whether the process is really alive.
+    (condition-case nil
+       (when (and (> (tramp-time-diff
+                      (current-time)
+                      (tramp-get-connection-property
+                       p "last-cmd-time" '(0 0 0)))
+                     60)
+                  p (processp p) (memq (process-status p) '(run open)))
+         (tramp-send-command vec "echo are you awake" t t)
+         (unless (and (memq (process-status p) '(run open))
+                      (tramp-wait-for-output p 10))
+           ;; The error will be caught locally.
+           (tramp-error vec 'file-error "Awake did fail")))
+      (file-error
+       (tramp-cleanup-connection vec t)
+       (setq p nil)))
+
+    ;; New connection must be opened.
+    (condition-case err
+       (unless (and p (processp p) (memq (process-status p) '(run open)))
+
+         ;; We call `tramp-get-buffer' in order to get a debug buffer
+         ;; for messages from the beginning.
+         (tramp-get-buffer vec)
+
+         ;; If `non-essential' is non-nil, don't reopen a new connection.
+         (when (and (boundp 'non-essential) (symbol-value 'non-essential))
+           (throw 'non-essential 'non-essential))
+
+         (with-tramp-progress-reporter
+             vec 3
+             (if (zerop (length (tramp-file-name-user vec)))
+                 (format "Opening connection for %s using %s"
                          (tramp-file-name-host vec)
-                         (tramp-file-name-method vec)))
+                         (tramp-file-name-method vec))
+               (format "Opening connection for %s@%s using %s"
+                       (tramp-file-name-user vec)
+                       (tramp-file-name-host vec)
+                       (tramp-file-name-method vec)))
 
+           (catch 'uname-changed
              ;; Start new process.
              (when (and p (processp p))
                (delete-process p))
@@ -4503,13 +4504,13 @@ connection if a previous connection has died for some reason."
                        target-alist (cdr target-alist)))
 
                ;; Make initial shell settings.
-               (tramp-open-connection-setup-interactive-shell p vec))))
+               (tramp-open-connection-setup-interactive-shell p vec)))))
 
-       ;; When the user did interrupt, we must cleanup.
-       (quit
-        (tramp-cleanup vec)
-        ;; Propagate the quit signal.
-        (signal (car err) (cdr err)))))))
+      ;; When the user did interrupt, we must cleanup.
+      (quit
+       (tramp-cleanup-connection vec t)
+       ;; Propagate the quit signal.
+       (signal (car err) (cdr err))))))
 
 (defun tramp-send-command (vec command &optional neveropen nooutput)
   "Send the COMMAND to connection VEC.
index 1d4880a9f32372234dc8ba450de626c4453935e6..27f3bd41e9c6fe0c7cc6e5314ba4e4dcc1766d88 100644 (file)
@@ -1726,8 +1726,10 @@ If ARGUMENT is non-nil, use it as argument for
                            (search-forward-regexp
                             tramp-smb-wrong-passwd-regexp nil t))
                       ;; Disable `auth-source' and `password-cache'.
+                      (tramp-message
+                       vec 3 "Retry connection with new password")
                       (let (auth-sources)
-                        (tramp-cleanup vec)
+                        (tramp-cleanup-connection vec t)
                         (tramp-smb-maybe-open-connection vec argument))
                     ;; Propagate the error.
                     (signal (car err) (cdr err)))))))))))))
index 6c1ee70b205d5d1094b3a537db2b50538285c8ad..fe4f7b8bb54acf1c97c21162ea5c7c34a56a438d 100644 (file)
@@ -1712,19 +1712,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
@@ -2147,7 +2134,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)))