]> git.eshelyaron.com Git - emacs.git/commitdiff
process-file in Tramp must return exit code (Bug#41099)
authorMichael Albinus <michael.albinus@gmx.de>
Wed, 6 May 2020 08:36:43 +0000 (10:36 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Wed, 6 May 2020 08:36:43 +0000 (10:36 +0200)
* 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.

lisp/net/tramp-adb.el
lisp/net/tramp-sh.el
test/lisp/net/tramp-tests.el

index aae25d1dbf3223d5a7c09fdac949d243cf1fb593..7f829f15205d2f3fd02015b9af7932bb63550b72 100644 (file)
@@ -896,14 +896,13 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
       ;; it.  Call it in a subshell, in order to preserve working
       ;; directory.
       (condition-case nil
-         (progn
-           (setq ret
-                 (if (tramp-adb-send-command-and-check
-                      v
-                      (format "(cd %s; %s)"
-                              (tramp-shell-quote-argument localname) command))
-                     ;; Set return status accordingly.
-                     0 1))
+         (unwind-protect
+             (setq ret (tramp-adb-send-command-and-check
+                        v (format
+                           "(cd %s; %s)"
+                           (tramp-shell-quote-argument localname) command)
+                        t))
+           (unless (natnump ret) (setq ret 1))
            ;; We should add the output anyway.
            (when outbuf
              (with-current-buffer outbuf
@@ -1186,11 +1185,14 @@ This happens for Android >= 4.0."
        (while (re-search-forward "\r+$" nil t)
          (replace-match "" nil nil))))))
 
-(defun tramp-adb-send-command-and-check (vec command)
+(defun tramp-adb-send-command-and-check (vec command &optional exit-status)
   "Run COMMAND and check its exit status.
 Sends `echo $?' along with the COMMAND for checking the exit
 status.  If COMMAND is nil, just sends `echo $?'.  Returns nil if
-the exit status is not equal 0, and t otherwise."
+the exit status is not equal 0, and t otherwise.
+
+Optional argument EXIT-STATUS, if non-nil, triggers the return of
+the exit status."
   (tramp-adb-send-command
    vec (if command
           (format "%s; echo tramp_exit_status $?" command)
@@ -1201,7 +1203,9 @@ the exit status is not equal 0, and t otherwise."
        vec 'file-error "Couldn't find exit status of `%s'" command))
     (skip-chars-forward "^ ")
     (prog1
-       (zerop (read (current-buffer)))
+       (if exit-status
+           (read (current-buffer))
+         (zerop (read (current-buffer))))
       (let ((inhibit-read-only t))
        (delete-region (match-beginning 0) (point-max))))))
 
index 592dcf671597524209846dd33dba4ac7c2fa00f9..c6eb7a8ff492aa3e91e4d69cabbb952af27a0251 100644 (file)
@@ -3136,13 +3136,12 @@ STDERR can also be a file name."
       ;; directory.
       (condition-case nil
          (unwind-protect
-              (setq ret
-                   (if (tramp-send-command-and-check
-                        v (format "cd %s && %s"
-                                  (tramp-shell-quote-argument localname)
-                                  command)
-                        t t)
-                       0 1))
+              (setq ret (tramp-send-command-and-check
+                        v (format
+                           "cd %s && %s"
+                           (tramp-shell-quote-argument localname) command)
+                        t t t))
+           (unless (natnump ret) (setq ret 1))
            ;; We should add the output anyway.
            (when outbuf
              (with-current-buffer outbuf
@@ -5239,7 +5238,7 @@ function waits for output unless NOOUTPUT is set."
       found)))
 
 (defun tramp-send-command-and-check
-  (vec command &optional subshell dont-suppress-err)
+  (vec command &optional subshell dont-suppress-err exit-status)
   "Run COMMAND and check its exit status.
 Send `echo $?' along with the COMMAND for checking the exit status.
 If COMMAND is nil, just send `echo $?'.  Return t if the exit
@@ -5247,7 +5246,9 @@ status is 0, and nil otherwise.
 
 If the optional argument SUBSHELL is non-nil, the command is
 executed in a subshell, ie surrounded by parentheses.  If
-DONT-SUPPRESS-ERR is non-nil, stderr won't be sent to /dev/null."
+DONT-SUPPRESS-ERR is non-nil, stderr won't be sent to /dev/null.
+Optional argument EXIT-STATUS, if non-nil, triggers the return of
+the exit status."
   (tramp-send-command
    vec
    (concat (if subshell "( " "")
@@ -5261,7 +5262,9 @@ DONT-SUPPRESS-ERR is non-nil, stderr won't be sent to /dev/null."
        vec 'file-error "Couldn't find exit status of `%s'" command))
     (skip-chars-forward "^ ")
     (prog1
-       (zerop (read (current-buffer)))
+       (if exit-status
+           (read (current-buffer))
+         (zerop (read (current-buffer))))
       (let ((inhibit-read-only t))
        (delete-region (match-beginning 0) (point-max))))))
 
index 28d20e39f8c0cb4199707c518ca772f101c99273..462539a7c1778566320ef74c6d03187bce04ab90 100644 (file)
@@ -4208,6 +4208,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
            (should (zerop (process-file "true")))
            (should-not (zerop (process-file "false")))
            (should-not (zerop (process-file "binary-does-not-exist")))
+           (should (= 42 (process-file "sh" nil nil nil "-c" "exit 42")))
            (with-temp-buffer
              (write-region "foo" nil tmp-name)
              (should (file-exists-p tmp-name))