1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-05 11:45:45 +00:00

* 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.
This commit is contained in:
Michael Albinus 2013-09-10 09:45:33 +02:00
parent 9a2c9b4764
commit 6480194ca1
6 changed files with 94 additions and 82 deletions

View 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)

View 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.

View File

@ -55,9 +55,11 @@
(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)))))

View 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))))
(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 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)))
;; 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)))
;; 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)
;; 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))
;; 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)
(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.

View 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)))))))))))))

View 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)))