...
 
Commits (2)
  • Michael Albinus's avatar
    ; Tramp cleanup · 492b31d9
    Michael Albinus authored
    * 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.
    492b31d9
  • Michael Albinus's avatar
    Adapt `accept-process-output' arguments in tramp-tests · b092a9af
    Michael Albinus authored
    * test/lisp/net/tramp-tests.el (tramp-test29-start-file-process)
    (tramp-test30-make-process, tramp-test31-interrupt-process)
    (tramp-test32-shell-command)
    (tramp--test-shell-command-to-string-asynchronously)
    (tramp-test43-asynchronous-requests):
    Adapt `accept-process-output' arguments.
    b092a9af
......@@ -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))
......
......@@ -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")
......
......@@ -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))
......
......@@ -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)
......
......@@ -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
......
......@@ -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)
......
......@@ -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]]"
......
......@@ -515,7 +515,7 @@ This checks also `file-name-as-directory', `file-name-directory',
(skip-unless tramp-archive-enabled)
(let ((tmp-name tramp-archive-test-archive)
(files '("." ".." "bar" "baz.tar" "foo.hrd" "foo.lnk" "foo.txt")))
(files '("." ".." "bar" "baz.tar" "foo.hrd" "foo.lnk" "foo.txt")))
(unwind-protect
(progn
(should (file-directory-p tmp-name))
......
......@@ -3818,7 +3818,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
;; Read output.
(with-timeout (10 (ert-fail "`start-file-process' timed out"))
(while (< (- (point-max) (point-min)) (length "foo"))
(accept-process-output proc 0.1)))
(while (accept-process-output proc 0 nil t))))
(should (string-equal (buffer-string) "foo")))
;; Cleanup.
......@@ -3836,7 +3836,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
;; Read output.
(with-timeout (10 (ert-fail "`start-file-process' timed out"))
(while (< (- (point-max) (point-min)) (length "foo"))
(accept-process-output proc 0.1)))
(while (accept-process-output proc 0 nil t))))
(should (string-equal (buffer-string) "foo")))
;; Cleanup.
......@@ -3857,7 +3857,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
;; Read output.
(with-timeout (10 (ert-fail "`start-file-process' timed out"))
(while (< (- (point-max) (point-min)) (length "foo"))
(accept-process-output proc 0.1)))
(while (accept-process-output proc 0 nil t))))
(should (string-equal (buffer-string) "foo")))
;; Cleanup.
......@@ -3890,7 +3890,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
;; Read output.
(with-timeout (10 (ert-fail "`make-process' timed out"))
(while (< (- (point-max) (point-min)) (length "foo"))
(accept-process-output proc 0.1)))
(while (accept-process-output proc 0 nil t))))
(should (string-equal (buffer-string) "foo")))
;; Cleanup.
......@@ -3910,7 +3910,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
;; Read output.
(with-timeout (10 (ert-fail "`make-process' timed out"))
(while (< (- (point-max) (point-min)) (length "foo"))
(accept-process-output proc 0.1)))
(while (accept-process-output proc 0 nil t))))
(should (string-equal (buffer-string) "foo")))
;; Cleanup.
......@@ -3935,7 +3935,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
;; Read output.
(with-timeout (10 (ert-fail "`make-process' timed out"))
(while (< (- (point-max) (point-min)) (length "foo"))
(accept-process-output proc 0.1)))
(while (accept-process-output proc 0 nil t))))
(should (string-equal (buffer-string) "foo")))
;; Cleanup.
......@@ -3958,8 +3958,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(delete-process proc)
;; Read output.
(with-timeout (10 (ert-fail "`make-process' timed out"))
(while (process-live-p proc)
(accept-process-output proc 0.1)))
(while (accept-process-output proc 0 nil t)))
(should (string-equal (buffer-string) "killed\n")))
;; Cleanup.
......@@ -3980,7 +3979,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(with-current-buffer stderr
(with-timeout (10 (ert-fail "`make-process' timed out"))
(while (= (point-min) (point-max))
(accept-process-output proc 0.1)))
(while (accept-process-output proc 0 nil t))))
(should
(string-equal (buffer-string) "cat: /: Is a directory\n"))))
......@@ -4007,7 +4006,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(should (numberp (process-get proc 'remote-pid)))
(should (interrupt-process proc))
;; Let the process accept the interrupt.
(accept-process-output proc 1 nil 0)
(while (accept-process-output proc nil nil 0))
(should-not (process-live-p proc))
;; An interrupted process cannot be interrupted, again.
(should-error (interrupt-process proc) :type 'error))
......@@ -4056,10 +4055,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(current-buffer))
;; Read output.
(with-timeout (10 (ert-fail "`async-shell-command' timed out"))
(while (< (- (point-max) (point-min))
(1+ (length (file-name-nondirectory tmp-name))))
(accept-process-output
(get-buffer-process (current-buffer)) 0.1)))
(while (accept-process-output
(get-buffer-process (current-buffer)) nil nil t)))
;; `ls' could produce colorized output.
(goto-char (point-min))
(while
......@@ -4087,10 +4084,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(format "%s\n" (file-name-nondirectory tmp-name)))
;; Read output.
(with-timeout (10 (ert-fail "`async-shell-command' timed out"))
(while (< (- (point-max) (point-min))
(1+ (length (file-name-nondirectory tmp-name))))
(accept-process-output
(get-buffer-process (current-buffer)) 0.1)))
(while (accept-process-output
(get-buffer-process (current-buffer)) nil nil t)))
;; `ls' could produce colorized output.
(goto-char (point-min))
(while
......@@ -4112,10 +4107,9 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
"Like `shell-command-to-string', but for asynchronous processes."
(with-temp-buffer
(async-shell-command command (current-buffer))
(with-timeout (10)
(while (get-buffer-process (current-buffer))
(accept-process-output (get-buffer-process (current-buffer)) 0.1)))
(accept-process-output nil 0.1)
(with-timeout (10 (ert-fail "`async-shell-command-to-string' timed out"))
(while (accept-process-output
(get-buffer-process (current-buffer)) nil nil t)))
(buffer-substring-no-properties (point-min) (point-max))))
;; This test is inspired by Bug#23952.
......@@ -5359,7 +5353,7 @@ process sentinels. They shall not disturb each other."
(should (file-attributes file)))
;; Send string to process.
(process-send-string proc (format "%s\n" (buffer-name buf)))
(accept-process-output proc 0.1 nil 0)
(while (accept-process-output proc 0 nil 0))
;; Give the watchdog a chance.
(read-event nil nil 0.01)
(tramp--test-message
......