diff options
| author | Michael Albinus | 2020-01-27 10:11:32 +0100 |
|---|---|---|
| committer | Michael Albinus | 2020-01-27 10:11:32 +0100 |
| commit | e1c93a02dd13039f7a9f4ccefddaa3e761a27a2e (patch) | |
| tree | d61cbea1be54bb1491663a1f69f28df1a1fd96f3 | |
| parent | 502059433ce0e9699eb73d21656ce6e9e127d63b (diff) | |
| download | emacs-e1c93a02dd13039f7a9f4ccefddaa3e761a27a2e.tar.gz emacs-e1c93a02dd13039f7a9f4ccefddaa3e761a27a2e.zip | |
Fix problems in Tramp's async-shell-command
* lisp/net/tramp-adb.el (tramp-adb-handle-make-process):
* lisp/net/tramp-cache.el (top):
* lisp/net/tramp-sh.el (tramp-sh-handle-make-process):
Use `insert-file-contents-literally'.
* lisp/net/tramp.el (tramp-parse-file):
Use `insert-file-contents-literally'.
(tramp-handle-shell-command): Reorganize error-buffer handling.
(tramp-handle-start-file-process): Use `consp' instead of `listp'.
* test/lisp/net/tramp-tests.el (tramp-test31-interrupt-process):
Bind `delete-exited-processes'.
(tramp--test-async-shell-command): Bind `delete-exited-processes'.
Add additional `accept-process-output'. Move cleanup of output
buffer ...
(tramp-test32-shell-command): ... here. Test error buffer also
for `async-shell-command'.
| -rw-r--r-- | lisp/net/tramp-adb.el | 6 | ||||
| -rw-r--r-- | lisp/net/tramp-cache.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-sh.el | 6 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 49 | ||||
| -rw-r--r-- | test/lisp/net/tramp-tests.el | 45 |
5 files changed, 61 insertions, 47 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 194dd2d308f..aa7fe147c20 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el | |||
| @@ -1065,13 +1065,15 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 1065 | ;; until the process is deleted. | 1065 | ;; until the process is deleted. |
| 1066 | (when (bufferp stderr) | 1066 | (when (bufferp stderr) |
| 1067 | (with-current-buffer stderr | 1067 | (with-current-buffer stderr |
| 1068 | (insert-file-contents remote-tmpstderr 'visit)) | 1068 | (insert-file-contents-literally |
| 1069 | remote-tmpstderr 'visit)) | ||
| 1069 | ;; Delete tmpstderr file. | 1070 | ;; Delete tmpstderr file. |
| 1070 | (add-function | 1071 | (add-function |
| 1071 | :after (process-sentinel p) | 1072 | :after (process-sentinel p) |
| 1072 | (lambda (_proc _msg) | 1073 | (lambda (_proc _msg) |
| 1073 | (with-current-buffer stderr | 1074 | (with-current-buffer stderr |
| 1074 | (insert-file-contents remote-tmpstderr 'visit)) | 1075 | (insert-file-contents-literally |
| 1076 | remote-tmpstderr 'visit nil nil 'replace)) | ||
| 1075 | (delete-file remote-tmpstderr)))) | 1077 | (delete-file remote-tmpstderr)))) |
| 1076 | ;; Return process. | 1078 | ;; Return process. |
| 1077 | p)))) | 1079 | p)))) |
diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index 6ce86b4b65d..92c98486f46 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el | |||
| @@ -504,7 +504,7 @@ for all methods. Resulting data are derived from connection history." | |||
| 504 | tramp-cache-read-persistent-data) | 504 | tramp-cache-read-persistent-data) |
| 505 | (condition-case err | 505 | (condition-case err |
| 506 | (with-temp-buffer | 506 | (with-temp-buffer |
| 507 | (insert-file-contents tramp-persistency-file-name) | 507 | (insert-file-contents-literally tramp-persistency-file-name) |
| 508 | (let ((list (read (current-buffer))) | 508 | (let ((list (read (current-buffer))) |
| 509 | (tramp-verbose 0) | 509 | (tramp-verbose 0) |
| 510 | element key item) | 510 | element key item) |
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 23ce048720d..b8f3c0d8c82 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el | |||
| @@ -3004,13 +3004,15 @@ STDERR can also be a file name." | |||
| 3004 | ;; the process is deleted. | 3004 | ;; the process is deleted. |
| 3005 | (when (bufferp stderr) | 3005 | (when (bufferp stderr) |
| 3006 | (with-current-buffer stderr | 3006 | (with-current-buffer stderr |
| 3007 | (insert-file-contents remote-tmpstderr 'visit)) | 3007 | (insert-file-contents-literally |
| 3008 | remote-tmpstderr 'visit)) | ||
| 3008 | ;; Delete tmpstderr file. | 3009 | ;; Delete tmpstderr file. |
| 3009 | (add-function | 3010 | (add-function |
| 3010 | :after (process-sentinel p) | 3011 | :after (process-sentinel p) |
| 3011 | (lambda (_proc _msg) | 3012 | (lambda (_proc _msg) |
| 3012 | (with-current-buffer stderr | 3013 | (with-current-buffer stderr |
| 3013 | (insert-file-contents remote-tmpstderr 'visit)) | 3014 | (insert-file-contents-literally |
| 3015 | remote-tmpstderr 'visit nil nil 'replace)) | ||
| 3014 | (delete-file remote-tmpstderr)))) | 3016 | (delete-file remote-tmpstderr)))) |
| 3015 | ;; Return process. | 3017 | ;; Return process. |
| 3016 | p))) | 3018 | p))) |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 61f6f2ed3a7..e5bb094bbd5 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -2844,7 +2844,7 @@ User is always nil." | |||
| 2844 | (let ((default-directory (tramp-compat-temporary-file-directory))) | 2844 | (let ((default-directory (tramp-compat-temporary-file-directory))) |
| 2845 | (when (file-readable-p filename) | 2845 | (when (file-readable-p filename) |
| 2846 | (with-temp-buffer | 2846 | (with-temp-buffer |
| 2847 | (insert-file-contents filename) | 2847 | (insert-file-contents-literally filename) |
| 2848 | (goto-char (point-min)) | 2848 | (goto-char (point-min)) |
| 2849 | (cl-loop while (not (eobp)) collect (funcall function)))))) | 2849 | (cl-loop while (not (eobp)) collect (funcall function)))))) |
| 2850 | 2850 | ||
| @@ -3699,32 +3699,37 @@ support symbolic links." | |||
| 3699 | ;; Run the process. | 3699 | ;; Run the process. |
| 3700 | (setq p (start-file-process-shell-command | 3700 | (setq p (start-file-process-shell-command |
| 3701 | (buffer-name output-buffer) buffer command)) | 3701 | (buffer-name output-buffer) buffer command)) |
| 3702 | (if (process-live-p p) | 3702 | ;; Insert error messages if they were separated. |
| 3703 | ;; Display output. | 3703 | (when (consp buffer) |
| 3704 | (with-current-buffer output-buffer | ||
| 3705 | (display-buffer output-buffer '(nil (allow-no-window . t))) | ||
| 3706 | (setq mode-line-process '(":%s")) | ||
| 3707 | (shell-mode) | ||
| 3708 | (set-process-filter p #'comint-output-filter) | ||
| 3709 | (set-process-sentinel | ||
| 3710 | p (if (listp buffer) | ||
| 3711 | (lambda (_proc _string) | ||
| 3712 | (with-current-buffer error-buffer | ||
| 3713 | (insert-file-contents (cadr buffer))) | ||
| 3714 | (delete-file (cadr buffer))) | ||
| 3715 | #'shell-command-sentinel))) | ||
| 3716 | ;; Show stderr. | ||
| 3717 | (with-current-buffer error-buffer | 3704 | (with-current-buffer error-buffer |
| 3718 | (insert-file-contents (cadr buffer))) | 3705 | (insert-file-contents-literally (cadr buffer)))) |
| 3719 | (delete-file (cadr buffer))))) | 3706 | (if (process-live-p p) |
| 3707 | ;; Display output. | ||
| 3708 | (with-current-buffer output-buffer | ||
| 3709 | (display-buffer output-buffer '(nil (allow-no-window . t))) | ||
| 3710 | (setq mode-line-process '(":%s")) | ||
| 3711 | (shell-mode) | ||
| 3712 | (set-process-filter p #'comint-output-filter) | ||
| 3713 | (set-process-sentinel p #'shell-command-sentinel) | ||
| 3714 | (when (consp buffer) | ||
| 3715 | (add-function | ||
| 3716 | :after (process-sentinel p) | ||
| 3717 | (lambda (_proc _string) | ||
| 3718 | (with-current-buffer error-buffer | ||
| 3719 | (insert-file-contents-literally | ||
| 3720 | (cadr buffer) nil nil nil 'replace)) | ||
| 3721 | (delete-file (cadr buffer)))))) | ||
| 3722 | |||
| 3723 | (when (consp buffer) | ||
| 3724 | (delete-file (cadr buffer)))))) | ||
| 3720 | 3725 | ||
| 3721 | (prog1 | 3726 | (prog1 |
| 3722 | ;; Run the process. | 3727 | ;; Run the process. |
| 3723 | (process-file-shell-command command nil buffer nil) | 3728 | (process-file-shell-command command nil buffer nil) |
| 3724 | ;; Insert error messages if they were separated. | 3729 | ;; Insert error messages if they were separated. |
| 3725 | (when (listp buffer) | 3730 | (when (consp buffer) |
| 3726 | (with-current-buffer error-buffer | 3731 | (with-current-buffer error-buffer |
| 3727 | (insert-file-contents (cadr buffer))) | 3732 | (insert-file-contents-literally (cadr buffer))) |
| 3728 | (delete-file (cadr buffer))) | 3733 | (delete-file (cadr buffer))) |
| 3729 | (if current-buffer-p | 3734 | (if current-buffer-p |
| 3730 | ;; This is like exchange-point-and-mark, but doesn't | 3735 | ;; This is like exchange-point-and-mark, but doesn't |
| @@ -3745,10 +3750,10 @@ BUFFER might be a list, in this case STDERR is separated." | |||
| 3745 | (tramp-file-name-handler | 3750 | (tramp-file-name-handler |
| 3746 | 'make-process | 3751 | 'make-process |
| 3747 | :name name | 3752 | :name name |
| 3748 | :buffer (if (listp buffer) (car buffer) buffer) | 3753 | :buffer (if (consp buffer) (car buffer) buffer) |
| 3749 | :command (and program (cons program args)) | 3754 | :command (and program (cons program args)) |
| 3750 | ;; `shell-command' adds an errfile to `buffer'. | 3755 | ;; `shell-command' adds an errfile to `buffer'. |
| 3751 | :stderr (when (listp buffer) (cadr buffer)) | 3756 | :stderr (when (consp buffer) (cadr buffer)) |
| 3752 | :noquery nil | 3757 | :noquery nil |
| 3753 | :file-handler t)) | 3758 | :file-handler t)) |
| 3754 | 3759 | ||
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 129652839c4..7ffd22e77be 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el | |||
| @@ -4410,6 +4410,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4410 | ;; order to establish the connection prior running an asynchronous | 4410 | ;; order to establish the connection prior running an asynchronous |
| 4411 | ;; process. | 4411 | ;; process. |
| 4412 | (let ((default-directory (file-truename tramp-test-temporary-file-directory)) | 4412 | (let ((default-directory (file-truename tramp-test-temporary-file-directory)) |
| 4413 | (delete-exited-processes t) | ||
| 4413 | kill-buffer-query-functions proc) | 4414 | kill-buffer-query-functions proc) |
| 4414 | (unwind-protect | 4415 | (unwind-protect |
| 4415 | (with-temp-buffer | 4416 | (with-temp-buffer |
| @@ -4436,18 +4437,14 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4436 | (command output-buffer &optional error-buffer input) | 4437 | (command output-buffer &optional error-buffer input) |
| 4437 | "Like `async-shell-command', reading the output. | 4438 | "Like `async-shell-command', reading the output. |
| 4438 | INPUT, if non-nil, is a string sent to the process." | 4439 | INPUT, if non-nil, is a string sent to the process." |
| 4439 | (let ((proc (async-shell-command command output-buffer error-buffer))) | 4440 | (let ((proc (async-shell-command command output-buffer error-buffer)) |
| 4441 | (delete-exited-processes t)) | ||
| 4440 | (when (stringp input) | 4442 | (when (stringp input) |
| 4441 | (process-send-string proc input)) | 4443 | (process-send-string proc input)) |
| 4442 | (with-timeout | 4444 | (with-timeout |
| 4443 | ((if (getenv "EMACS_EMBA_CI") 30 10) (tramp--test-timeout-handler)) | 4445 | ((if (getenv "EMACS_EMBA_CI") 30 10) (tramp--test-timeout-handler)) |
| 4444 | (while (accept-process-output proc nil nil t)) | 4446 | (while (or (accept-process-output proc nil nil t) (process-live-p proc)))) |
| 4445 | (should-not (process-live-p proc))) | 4447 | (accept-process-output proc nil nil t))) |
| 4446 | ;; `ls' could produce colorized output. | ||
| 4447 | (with-current-buffer output-buffer | ||
| 4448 | (goto-char (point-min)) | ||
| 4449 | (while (re-search-forward tramp-display-escape-sequence-regexp nil t) | ||
| 4450 | (replace-match "" nil nil))))) | ||
| 4451 | 4448 | ||
| 4452 | (defun tramp--test-shell-command-to-string-asynchronously (command) | 4449 | (defun tramp--test-shell-command-to-string-asynchronously (command) |
| 4453 | "Like `shell-command-to-string', but for asynchronous processes." | 4450 | "Like `shell-command-to-string', but for asynchronous processes." |
| @@ -4486,26 +4483,33 @@ INPUT, if non-nil, is a string sent to the process." | |||
| 4486 | this-shell-command | 4483 | this-shell-command |
| 4487 | (format "ls %s" (file-name-nondirectory tmp-name)) | 4484 | (format "ls %s" (file-name-nondirectory tmp-name)) |
| 4488 | (current-buffer)) | 4485 | (current-buffer)) |
| 4486 | ;; `ls' could produce colorized output. | ||
| 4487 | (goto-char (point-min)) | ||
| 4488 | (while | ||
| 4489 | (re-search-forward tramp-display-escape-sequence-regexp nil t) | ||
| 4490 | (replace-match "" nil nil)) | ||
| 4489 | (should | 4491 | (should |
| 4490 | (string-equal | 4492 | (string-equal |
| 4491 | (format "%s\n" (file-name-nondirectory tmp-name)) | 4493 | (format "%s\n" (file-name-nondirectory tmp-name)) |
| 4492 | (buffer-string)))) | 4494 | (buffer-string)))) |
| 4493 | 4495 | ||
| 4494 | ;; Cleanup. | 4496 | ;; Cleanup. |
| 4495 | (ignore-errors (delete-file tmp-name)))) | 4497 | (ignore-errors (delete-file tmp-name))) |
| 4496 | 4498 | ||
| 4497 | ;; Test `shell-command' with error buffer. | 4499 | ;; Test `{async-}shell-command' with error buffer. |
| 4498 | (let ((stderr (generate-new-buffer "*stderr*"))) | 4500 | (let ((stderr (generate-new-buffer "*stderr*"))) |
| 4499 | (unwind-protect | 4501 | (unwind-protect |
| 4500 | (with-temp-buffer | 4502 | (with-temp-buffer |
| 4501 | (shell-command "echo foo; echo bar >&2" (current-buffer) stderr) | 4503 | (funcall |
| 4502 | (should (string-equal "foo\n" (buffer-string))) | 4504 | this-shell-command |
| 4503 | ;; Check stderr. | 4505 | "echo foo >&2; echo bar" (current-buffer) stderr) |
| 4504 | (with-current-buffer stderr | 4506 | (should (string-equal "bar\n" (buffer-string))) |
| 4505 | (should (string-equal "bar\n" (buffer-string))))) | 4507 | ;; Check stderr. |
| 4508 | (with-current-buffer stderr | ||
| 4509 | (should (string-equal "foo\n" (buffer-string))))) | ||
| 4506 | 4510 | ||
| 4507 | ;; Cleanup. | 4511 | ;; Cleanup. |
| 4508 | (ignore-errors (kill-buffer stderr)))) | 4512 | (ignore-errors (kill-buffer stderr))))) |
| 4509 | 4513 | ||
| 4510 | ;; Test sending string to `async-shell-command'. | 4514 | ;; Test sending string to `async-shell-command'. |
| 4511 | (unwind-protect | 4515 | (unwind-protect |
| @@ -4514,6 +4518,7 @@ INPUT, if non-nil, is a string sent to the process." | |||
| 4514 | (should (file-exists-p tmp-name)) | 4518 | (should (file-exists-p tmp-name)) |
| 4515 | (tramp--test-async-shell-command | 4519 | (tramp--test-async-shell-command |
| 4516 | "read line; ls $line" (current-buffer) nil | 4520 | "read line; ls $line" (current-buffer) nil |
| 4521 | ;; String to be sent. | ||
| 4517 | (format "%s\n" (file-name-nondirectory tmp-name))) | 4522 | (format "%s\n" (file-name-nondirectory tmp-name))) |
| 4518 | (should | 4523 | (should |
| 4519 | (string-equal | 4524 | (string-equal |