aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2020-05-06 10:36:43 +0200
committerMichael Albinus2020-05-06 10:36:43 +0200
commitd9e10a1d1a56b8740a276a3fa418f628f79790d0 (patch)
tree0474bd7a5e37e0165e73ba5818cd1b0316fe6112
parentc4adfbae24d920f0ce62cb88b988219348d1ec73 (diff)
downloademacs-d9e10a1d1a56b8740a276a3fa418f628f79790d0.tar.gz
emacs-d9e10a1d1a56b8740a276a3fa418f628f79790d0.zip
process-file in Tramp must return exit code (Bug#41099)
* lisp/net/tramp-adb.el (tramp-adb-send-command-and-check): Add optional argument EXIT-STATUS. (tramp-adb-handle-process-file): Use it. * lisp/net/tramp-sh.el (tramp-send-command-and-check): Add optional argument EXIT-STATUS. (tramp-sh-handle-process-file): Use it. (Bug#41099) * test/lisp/net/tramp-tests.el (tramp-test28-process-file): Adapt test.
-rw-r--r--lisp/net/tramp-adb.el26
-rw-r--r--lisp/net/tramp-sh.el23
-rw-r--r--test/lisp/net/tramp-tests.el1
3 files changed, 29 insertions, 21 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index aae25d1dbf3..7f829f15205 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -896,14 +896,13 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
896 ;; it. Call it in a subshell, in order to preserve working 896 ;; it. Call it in a subshell, in order to preserve working
897 ;; directory. 897 ;; directory.
898 (condition-case nil 898 (condition-case nil
899 (progn 899 (unwind-protect
900 (setq ret 900 (setq ret (tramp-adb-send-command-and-check
901 (if (tramp-adb-send-command-and-check 901 v (format
902 v 902 "(cd %s; %s)"
903 (format "(cd %s; %s)" 903 (tramp-shell-quote-argument localname) command)
904 (tramp-shell-quote-argument localname) command)) 904 t))
905 ;; Set return status accordingly. 905 (unless (natnump ret) (setq ret 1))
906 0 1))
907 ;; We should add the output anyway. 906 ;; We should add the output anyway.
908 (when outbuf 907 (when outbuf
909 (with-current-buffer outbuf 908 (with-current-buffer outbuf
@@ -1186,11 +1185,14 @@ This happens for Android >= 4.0."
1186 (while (re-search-forward "\r+$" nil t) 1185 (while (re-search-forward "\r+$" nil t)
1187 (replace-match "" nil nil)))))) 1186 (replace-match "" nil nil))))))
1188 1187
1189(defun tramp-adb-send-command-and-check (vec command) 1188(defun tramp-adb-send-command-and-check (vec command &optional exit-status)
1190 "Run COMMAND and check its exit status. 1189 "Run COMMAND and check its exit status.
1191Sends `echo $?' along with the COMMAND for checking the exit 1190Sends `echo $?' along with the COMMAND for checking the exit
1192status. If COMMAND is nil, just sends `echo $?'. Returns nil if 1191status. If COMMAND is nil, just sends `echo $?'. Returns nil if
1193the exit status is not equal 0, and t otherwise." 1192the exit status is not equal 0, and t otherwise.
1193
1194Optional argument EXIT-STATUS, if non-nil, triggers the return of
1195the exit status."
1194 (tramp-adb-send-command 1196 (tramp-adb-send-command
1195 vec (if command 1197 vec (if command
1196 (format "%s; echo tramp_exit_status $?" command) 1198 (format "%s; echo tramp_exit_status $?" command)
@@ -1201,7 +1203,9 @@ the exit status is not equal 0, and t otherwise."
1201 vec 'file-error "Couldn't find exit status of `%s'" command)) 1203 vec 'file-error "Couldn't find exit status of `%s'" command))
1202 (skip-chars-forward "^ ") 1204 (skip-chars-forward "^ ")
1203 (prog1 1205 (prog1
1204 (zerop (read (current-buffer))) 1206 (if exit-status
1207 (read (current-buffer))
1208 (zerop (read (current-buffer))))
1205 (let ((inhibit-read-only t)) 1209 (let ((inhibit-read-only t))
1206 (delete-region (match-beginning 0) (point-max)))))) 1210 (delete-region (match-beginning 0) (point-max))))))
1207 1211
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 592dcf67159..c6eb7a8ff49 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3136,13 +3136,12 @@ STDERR can also be a file name."
3136 ;; directory. 3136 ;; directory.
3137 (condition-case nil 3137 (condition-case nil
3138 (unwind-protect 3138 (unwind-protect
3139 (setq ret 3139 (setq ret (tramp-send-command-and-check
3140 (if (tramp-send-command-and-check 3140 v (format
3141 v (format "cd %s && %s" 3141 "cd %s && %s"
3142 (tramp-shell-quote-argument localname) 3142 (tramp-shell-quote-argument localname) command)
3143 command) 3143 t t t))
3144 t t) 3144 (unless (natnump ret) (setq ret 1))
3145 0 1))
3146 ;; We should add the output anyway. 3145 ;; We should add the output anyway.
3147 (when outbuf 3146 (when outbuf
3148 (with-current-buffer outbuf 3147 (with-current-buffer outbuf
@@ -5239,7 +5238,7 @@ function waits for output unless NOOUTPUT is set."
5239 found))) 5238 found)))
5240 5239
5241(defun tramp-send-command-and-check 5240(defun tramp-send-command-and-check
5242 (vec command &optional subshell dont-suppress-err) 5241 (vec command &optional subshell dont-suppress-err exit-status)
5243 "Run COMMAND and check its exit status. 5242 "Run COMMAND and check its exit status.
5244Send `echo $?' along with the COMMAND for checking the exit status. 5243Send `echo $?' along with the COMMAND for checking the exit status.
5245If COMMAND is nil, just send `echo $?'. Return t if the exit 5244If COMMAND is nil, just send `echo $?'. Return t if the exit
@@ -5247,7 +5246,9 @@ status is 0, and nil otherwise.
5247 5246
5248If the optional argument SUBSHELL is non-nil, the command is 5247If the optional argument SUBSHELL is non-nil, the command is
5249executed in a subshell, ie surrounded by parentheses. If 5248executed in a subshell, ie surrounded by parentheses. If
5250DONT-SUPPRESS-ERR is non-nil, stderr won't be sent to /dev/null." 5249DONT-SUPPRESS-ERR is non-nil, stderr won't be sent to /dev/null.
5250Optional argument EXIT-STATUS, if non-nil, triggers the return of
5251the exit status."
5251 (tramp-send-command 5252 (tramp-send-command
5252 vec 5253 vec
5253 (concat (if subshell "( " "") 5254 (concat (if subshell "( " "")
@@ -5261,7 +5262,9 @@ DONT-SUPPRESS-ERR is non-nil, stderr won't be sent to /dev/null."
5261 vec 'file-error "Couldn't find exit status of `%s'" command)) 5262 vec 'file-error "Couldn't find exit status of `%s'" command))
5262 (skip-chars-forward "^ ") 5263 (skip-chars-forward "^ ")
5263 (prog1 5264 (prog1
5264 (zerop (read (current-buffer))) 5265 (if exit-status
5266 (read (current-buffer))
5267 (zerop (read (current-buffer))))
5265 (let ((inhibit-read-only t)) 5268 (let ((inhibit-read-only t))
5266 (delete-region (match-beginning 0) (point-max)))))) 5269 (delete-region (match-beginning 0) (point-max))))))
5267 5270
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 28d20e39f8c..462539a7c17 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -4208,6 +4208,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4208 (should (zerop (process-file "true"))) 4208 (should (zerop (process-file "true")))
4209 (should-not (zerop (process-file "false"))) 4209 (should-not (zerop (process-file "false")))
4210 (should-not (zerop (process-file "binary-does-not-exist"))) 4210 (should-not (zerop (process-file "binary-does-not-exist")))
4211 (should (= 42 (process-file "sh" nil nil nil "-c" "exit 42")))
4211 (with-temp-buffer 4212 (with-temp-buffer
4212 (write-region "foo" nil tmp-name) 4213 (write-region "foo" nil tmp-name)
4213 (should (file-exists-p tmp-name)) 4214 (should (file-exists-p tmp-name))