; Tramp cleanup

* lisp/net/tramp-adb.el (tramp-adb-maybe-open-connection):
Handle `non-essential'.

* lisp/net/tramp-archive.el: Increase `max-specpdl-size' when
loading tramp-gvfs.

* lisp/net/tramp-rclone.el (tramp-rclone-mounted-p): Reorder for
better traces.
(tramp-rclone-maybe-open-connection): Handle `non-essential'.

* lisp/net/tramp-sh.el (tramp-sh-handle-copy-directory)
(tramp-find-inline-encoding): Simplify check.

* lisp/net/tramp-smb.el (tramp-smb-handle-insert-directory)
(tramp-smb-handle-insert-directory): Simplify check.

* lisp/net/tramp-sudoedit.el (tramp-sudoedit-action-sudo):
Simplify check.
(tramp-sudoedit-maybe-open-connection): Handle `non-essential'.

* lisp/net/tramp.el (tramp-handle-load, tramp-wait-for-regexp):
Simplify check.
(tramp-action-login, tramp-action-password, tramp-action-yesno)
(tramp-action-yn, tramp-action-terminal): Return explicitly t.
(tramp-process-one-action, tramp-process-actions): Adapt docstring.
This commit is contained in:
Michael Albinus 2019-01-29 17:25:36 +01:00
parent 137b65a9b0
commit 492b31d977
7 changed files with 83 additions and 30 deletions

View file

@ -1300,6 +1300,14 @@ connection if a previous connection has died for some reason."
(tramp-error vec 'file-error "Cannot switch to user `%s'" user))
(unless (process-live-p p)
;; During completion, don't reopen a new connection. We check
;; this for the process related to `tramp-buffer-name';
;; otherwise `start-file-process' wouldn't run ever when
;; `non-essential' is non-nil.
(when (and (tramp-completion-mode-p)
(null (get-process (tramp-buffer-name vec))))
(throw 'non-essential 'non-essential))
(save-match-data
(when (and p (processp p)) (delete-process p))
(if (zerop (length device))

View file

@ -108,7 +108,10 @@
;;; Code:
(eval-when-compile (require 'cl-lib))
(require 'tramp-gvfs)
;; Sometimes, compilation fails with "Variable binding depth exceeds
;; max-specpdl-size".
(eval-and-compile
(let ((max-specpdl-size (* 2 max-specpdl-size))) (require 'tramp-gvfs)))
(autoload 'dired-uncache "dired")
(autoload 'url-tramp-convert-url-to-tramp "url-tramp")

View file

@ -467,19 +467,19 @@ file names."
(when (tramp-get-connection-process vec)
;; We cannot use `with-connection-property', because we don't want
;; to cache a nil result.
(or (tramp-get-connection-property
(tramp-get-connection-process vec) "mounted" nil)
(unless (tramp-get-connection-property
(tramp-get-connection-process vec) "mounted" nil)
(let* ((default-directory temporary-file-directory)
(mount (shell-command-to-string "mount -t fuse.rclone")))
(tramp-message vec 6 "%s" "mount -t fuse.rclone")
(tramp-message vec 6 "\n%s" mount)
(tramp-set-connection-property
(tramp-get-connection-process vec) "mounted"
(let* ((default-directory temporary-file-directory)
(mount (shell-command-to-string "mount -t fuse.rclone")))
(tramp-message vec 6 "%s" "mount -t fuse.rclone")
(tramp-message vec 6 "\n%s" mount)
(when (string-match
(format
"^\\(%s:\\S-*\\)" (regexp-quote (tramp-file-name-host vec)))
mount)
(match-string 1 mount)))))))
(when (string-match
(format
"^\\(%s:\\S-*\\)" (regexp-quote (tramp-file-name-host vec)))
mount)
(match-string 1 mount)))))))
(defun tramp-rclone-flush-directory-cache (vec)
"Flush directory cache of VEC mount."
@ -544,6 +544,14 @@ connection if a previous connection has died for some reason."
(if (zerop (length host))
(tramp-error vec 'file-error "Storage %s not connected" host))
;; During completion, don't reopen a new connection. We check
;; this for the process related to `tramp-buffer-name';
;; otherwise `start-file-process' wouldn't run ever when
;; `non-essential' is non-nil.
(when (and (tramp-completion-mode-p)
(null (get-process (tramp-buffer-name vec))))
(throw 'non-essential 'non-essential))
;; We need a process bound to the connection buffer. Therefore,
;; we create a dummy process. Maybe there is a better solution?
(unless (get-buffer-process (tramp-get-connection-buffer vec))

View file

@ -1931,7 +1931,7 @@ tramp-sh-handle-file-name-all-completions: internal error accessing `%s': `%s'"
(setq newname
(expand-file-name
(file-name-nondirectory dirname) newname)))
(when (not (file-directory-p (file-name-directory newname)))
(unless (file-directory-p (file-name-directory newname))
(make-directory (file-name-directory newname) parents))
(tramp-do-copy-or-rename-file-out-of-band
'copy dirname newname keep-date))
@ -4458,7 +4458,7 @@ Goes through the list `tramp-local-coding-commands' and
;; actually check the output it gives. And also, when
;; redirecting "mimencode" output to /dev/null, then as root
;; it might change the permissions of /dev/null!
(when (not (stringp rem-enc))
(unless (stringp rem-enc)
(let ((name (symbol-name rem-enc)))
(while (string-match "-" name)
(setq name (replace-match "_" nil t name)))
@ -4471,7 +4471,7 @@ Goes through the list `tramp-local-coding-commands' and
vec (format "%s </dev/null" rem-enc) t)
(throw 'wont-work-remote nil))
(when (not (stringp rem-dec))
(unless (stringp rem-dec)
(let ((name (symbol-name rem-dec))
(value (symbol-value rem-dec))
tmpfile)

View file

@ -1048,7 +1048,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(when (string-match-p "F" switches)
(mapc
(lambda (x)
(when (not (zerop (length (car x))))
(unless (zerop (length (car x)))
(cond
((char-equal ?d (string-to-char (nth 1 x)))
(setcar x (concat (car x) "/")))
@ -1066,7 +1066,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
;; Print entries.
(mapc
(lambda (x)
(when (not (zerop (length (nth 0 x))))
(unless (zerop (length (nth 0 x)))
(let ((attr
(when (tramp-smb-get-stat-capability v)
(ignore-errors

View file

@ -747,7 +747,7 @@ ID-FORMAT valid values are `string' and `integer'."
"Check, whether a sudo process has finished.
Remove unneeded output."
;; There might be pending output for the exit status.
(when (not (process-live-p proc))
(unless (process-live-p proc)
(while (tramp-accept-process-output proc 0))
;; Delete narrowed region, it would be in the way reading a Lisp form.
(goto-char (point-min))
@ -768,6 +768,15 @@ connection if a previous connection has died for some reason."
;; We need a process bound to the connection buffer. Therefore, we
;; create a dummy process. Maybe there is a better solution?
(unless (tramp-get-connection-process vec)
;; During completion, don't reopen a new connection. We check
;; this for the process related to `tramp-buffer-name'; otherwise
;; `start-file-process' wouldn't run ever when `non-essential' is
;; non-nil.
(when (and (tramp-completion-mode-p)
(null (get-process (tramp-buffer-name vec))))
(throw 'non-essential 'non-essential))
(let ((p (make-network-process
:name (tramp-buffer-name vec)
:buffer (tramp-get-connection-buffer vec)

View file

@ -3595,10 +3595,9 @@ User is always nil."
(tramp-error
v 'file-error
"File `%s' does not include a `.el' or `.elc' suffix" file)))
(unless noerror
(when (not (file-exists-p file))
(tramp-error
v tramp-file-missing "Cannot load nonexistent file `%s'" file)))
(unless (or noerror (file-exists-p file))
(tramp-error
v tramp-file-missing "Cannot load nonexistent file `%s'" file))
(if (not (file-exists-p file))
nil
(let ((tramp-message-show-message (not nomessage)))
@ -3902,7 +3901,8 @@ of."
(with-current-buffer (tramp-get-connection-buffer vec)
(tramp-message vec 6 "\n%s" (buffer-string)))
(tramp-message vec 3 "Sending login name `%s'" user)
(tramp-send-string vec (concat user tramp-local-end-of-line))))
(tramp-send-string vec (concat user tramp-local-end-of-line)))
t)
(defun tramp-action-password (proc vec)
"Query the user for a password."
@ -3922,7 +3922,8 @@ of."
(process-send-string
proc (concat (tramp-read-passwd proc) tramp-local-end-of-line))
;; Hide password prompt.
(narrow-to-region (point-max) (point-max)))))
(narrow-to-region (point-max) (point-max))))
t)
(defun tramp-action-succeed (_proc _vec)
"Signal success in finding shell prompt."
@ -3945,7 +3946,8 @@ See also `tramp-action-yn'."
(throw 'tramp-action 'permission-denied))
(with-current-buffer (tramp-get-connection-buffer vec)
(tramp-message vec 6 "\n%s" (buffer-string)))
(tramp-send-string vec (concat "yes" tramp-local-end-of-line)))))
(tramp-send-string vec (concat "yes" tramp-local-end-of-line))))
t)
(defun tramp-action-yn (proc vec)
"Ask the user for confirmation using `y-or-n-p'.
@ -3959,7 +3961,8 @@ See also `tramp-action-yesno'."
(throw 'tramp-action 'permission-denied))
(with-current-buffer (tramp-get-connection-buffer vec)
(tramp-message vec 6 "\n%s" (buffer-string)))
(tramp-send-string vec (concat "y" tramp-local-end-of-line)))))
(tramp-send-string vec (concat "y" tramp-local-end-of-line))))
t)
(defun tramp-action-terminal (_proc vec)
"Tell the remote host which terminal type to use.
@ -3967,7 +3970,8 @@ The terminal type can be configured with `tramp-terminal-type'."
(tramp-message vec 5 "Setting `%s' as terminal type." tramp-terminal-type)
(with-current-buffer (tramp-get-connection-buffer vec)
(tramp-message vec 6 "\n%s" (buffer-string)))
(tramp-send-string vec (concat tramp-terminal-type tramp-local-end-of-line)))
(tramp-send-string vec (concat tramp-terminal-type tramp-local-end-of-line))
t)
(defun tramp-action-process-alive (proc _vec)
"Check, whether a process has finished."
@ -4001,7 +4005,8 @@ The terminal type can be configured with `tramp-terminal-type'."
;;; Functions for processing the actions:
(defun tramp-process-one-action (proc vec actions)
"Wait for output from the shell and perform one action."
"Wait for output from the shell and perform one action.
See `tramp-process-actions' for the format of ACTIONS."
(let ((case-fold-search t)
found todo item pattern action)
(while (not found)
@ -4024,7 +4029,27 @@ The terminal type can be configured with `tramp-terminal-type'."
"Perform ACTIONS until success or TIMEOUT.
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."
connection buffer.
ACTIONS is a list of (PATTERN ACTION). The PATTERN should be a
symbol, a variable. The value of this variable gives the regular
expression to search for. Note that the regexp must match at the
end of the buffer, \"\\'\" is implicitly appended to it.
The ACTION should also be a symbol, but a function. When the
corresponding PATTERN matches, the ACTION function is called.
An ACTION function has two arguments (PROC VEC). If it returns
nil, nothing has been done, and the next action shall be called.
A non-nil return value indicates that the process output has been
consumed, and new output shall be retrieved, before starting to
process all ACTIONs, again. The same happens after calling the
last ACTION.
If an action determines, that all processing has been done (e.g.,
because the shell prompt has been detected), it shall throw a
result. The symbol `ok' means that all ACTIONs have been
performed successfully. Any other value means an error."
;; Enable `auth-source', unless "emacs -Q" has been called. We must
;; use the "password-vector" property in case we have several hops.
(tramp-set-connection-property
@ -4156,7 +4181,7 @@ nil."
nil proc 'file-error "Process has died"))
(setq found (tramp-check-for-regexp proc regexp)))))
(tramp-message proc 6 "\n%s" (buffer-string))
(when (not found)
(unless found
(if timeout
(tramp-error
proc 'file-error "[[Regexp `%s' not found in %d secs]]"