]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Bug#24394, Bug#34172
authorMichael Albinus <michael.albinus@gmx.de>
Fri, 22 Mar 2019 13:38:06 +0000 (14:38 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Fri, 22 Mar 2019 13:38:06 +0000 (14:38 +0100)
* lisp/subr.el (process-file-shell-command):
Use `with-connection-local-variables'.  Do not set "/bin/sh" for
remote buffers, trust settings of `shell-file-name'.

* lisp/net/tramp-adb.el (tramp-methods) <adb>:
* lisp/net/tramp-smb.el (tramp-methods) <smb>:
Remove `tramp-remote-shell' and `tramp-remote-shell-args'.

* lisp/net/tramp-sh.el (tramp-sh-handle-file-notify-add-watch)
(tramp-maybe-open-connection): Use proper read syntax for function
names.

* lisp/net/tramp.el (tramp-handle-shell-command): Do not use shell
file names from `tramp-methods'.
Respect `async-shell-command-buffer'.  (Bug#24394, Bug#34172)
Use `start-file-process-shell-command' and `process-file-shell-command'.

* test/lisp/net/tramp-tests.el (tramp-test32-shell-command):
Let it run partly for tramp-adb.

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

index 632ad12667d0a92bc34cd63fbb94bf2e31c2cada..8eeaa8be415151aad659eac4e4e473be31cf3a05 100644 (file)
@@ -78,9 +78,6 @@ It is used for TCP/IP devices."
 (tramp--with-startup
  (add-to-list 'tramp-methods
              `(,tramp-adb-method
-                ;; Used in `tramp-handle-shell-command'.
-                (tramp-remote-shell      "/system/bin/sh")
-                (tramp-remote-shell-args ("-c"))
                (tramp-tmpdir            "/data/local/tmp")
                 (tramp-default-port      5555)))
 
index d9edcb14198603f18669712f4bca6062d9025668..2b4399f8de744b0ce5cae70ab2229ac8c6660a53 100644 (file)
@@ -3619,7 +3619,7 @@ Fall back to normal file name handler if no Tramp handler exists."
              sequence `(,command "monitor" ,localname)))
        ;; "gvfs-monitor-dir".
        ((setq command (tramp-get-remote-gvfs-monitor-dir v))
-       (setq filter 'tramp-sh-gvfs-monitor-dir-process-filter
+       (setq filter #'tramp-sh-gvfs-monitor-dir-process-filter
              events
              (cond
               ((and (memq 'change flags) (memq 'attribute-change flags))
@@ -4886,7 +4886,7 @@ connection if a previous connection has died for some reason."
                             (list tramp-encoding-shell))))))
 
                ;; Set sentinel and query flag.  Initialize variables.
-               (set-process-sentinel p 'tramp-process-sentinel)
+               (set-process-sentinel p #'tramp-process-sentinel)
                (process-put p 'vector vec)
                (process-put p 'adjust-window-size-function #'ignore)
                (set-process-query-on-exit-flag p nil)
index e6e2485ea0fe8cf2a28a0a10ab98c44d0be2bc6f..66476305c2b3753870d6d2db07d6d710d070983a 100644 (file)
   (tramp--with-startup
    (add-to-list 'tramp-methods
                 `(,tramp-smb-method
-                  ;; We define an empty command, because
-                  ;; `tramp-smb-call-winexe' opens already the powershell.
-                  ;; Used in `tramp-handle-shell-command'.
-                  (tramp-remote-shell "")
                   ;; This is just a guess.  We don't know whether the share "C$"
                   ;; is available for public use, and whether the user has write
                   ;; access.
index 97ec5e174b47b31f8c311523de2eb90cbb48e4b4..48c363a873a47a709e98671567810bd8a9768449 100644 (file)
@@ -3569,17 +3569,7 @@ support symbolic links."
   (command &optional output-buffer error-buffer)
   "Like `shell-command' for Tramp files."
   (let* ((asynchronous (string-match-p "[ \t]*&[ \t]*\\'" command))
-        ;; We cannot use `shell-file-name' and `shell-command-switch',
-        ;; they are variables of the local host.
-        (args (append
-               (cons
-                (tramp-get-method-parameter
-                 (tramp-dissect-file-name default-directory)
-                 'tramp-remote-shell)
-                (tramp-get-method-parameter
-                 (tramp-dissect-file-name default-directory)
-                 'tramp-remote-shell-args))
-               (list (substring command 0 asynchronous))))
+        (command (substring command 0 asynchronous))
         current-buffer-p
         (output-buffer
          (cond
@@ -3596,19 +3586,48 @@ support symbolic links."
          (cond
           ((bufferp error-buffer) error-buffer)
           ((stringp error-buffer) (get-buffer-create error-buffer))))
-        (buffer
-         (if (and (not asynchronous) error-buffer)
-             (with-parsed-tramp-file-name default-directory nil
-               (list output-buffer (tramp-make-tramp-temp-file v)))
-           output-buffer))
-        (p (get-buffer-process output-buffer)))
-
-    ;; Check whether there is another process running.  Tramp does not
-    ;; support 2 (asynchronous) processes in parallel.
+        (bname (buffer-name output-buffer))
+        (p (get-buffer-process output-buffer))
+        buffer)
+
+    ;; The following code is taken from `shell-command', slightly
+    ;; adapted.  Shouldn't it be factored out?
     (when p
-      (if (yes-or-no-p "A command is running.  Kill it? ")
-         (ignore-errors (kill-process p))
-       (tramp-user-error p "Shell command in progress")))
+      (cond
+       ((eq async-shell-command-buffer 'confirm-kill-process)
+       ;; If will kill a process, query first.
+       (if (yes-or-no-p
+            "A command is running in the default buffer.  Kill it? ")
+           (kill-process p)
+         (tramp-user-error p "Shell command in progress")))
+       ((eq async-shell-command-buffer 'confirm-new-buffer)
+       ;; If will create a new buffer, query first.
+       (if (yes-or-no-p
+            "A command is running in the default buffer.  Use a new buffer? ")
+            (setq output-buffer (generate-new-buffer bname))
+         (tramp-user-error p "Shell command in progress")))
+       ((eq async-shell-command-buffer 'new-buffer)
+       ;; It will create a new buffer.
+        (setq output-buffer (generate-new-buffer bname)))
+       ((eq async-shell-command-buffer 'confirm-rename-buffer)
+       ;; If will rename the buffer, query first.
+       (if (yes-or-no-p
+            "A command is running in the default buffer.  Rename it? ")
+           (progn
+             (with-current-buffer output-buffer
+               (rename-uniquely))
+              (setq output-buffer (get-buffer-create bname)))
+         (tramp-user-error p "Shell command in progress")))
+       ((eq async-shell-command-buffer 'rename-buffer)
+       ;; It will rename the buffer.
+       (with-current-buffer output-buffer
+         (rename-uniquely))
+        (setq output-buffer (get-buffer-create bname)))))
+
+    (setq buffer (if (and (not asynchronous) error-buffer)
+                    (with-parsed-tramp-file-name default-directory nil
+                      (list output-buffer (tramp-make-tramp-temp-file v)))
+                  output-buffer))
 
     (if current-buffer-p
        (progn
@@ -3621,18 +3640,19 @@ support symbolic links."
     (if (and (not current-buffer-p) (integerp asynchronous))
        (prog1
            ;; Run the process.
-           (setq p (apply #'start-file-process "*Async Shell*" buffer args))
+           (setq p (start-file-process-shell-command
+                    "*Async Shell*" buffer command))
          ;; Display output.
          (with-current-buffer output-buffer
            (display-buffer output-buffer '(nil (allow-no-window . t)))
            (setq mode-line-process '(":%s"))
            (shell-mode)
            (set-process-sentinel p #'shell-command-sentinel)
-           (set-process-filter p 'comint-output-filter)))
+           (set-process-filter p #'comint-output-filter)))
 
       (prog1
          ;; Run the process.
-         (apply #'process-file (car args) nil buffer nil (cdr args))
+         (process-file-shell-command command nil buffer nil)
        ;; Insert error messages if they were separated.
        (when (listp buffer)
          (with-current-buffer error-buffer
index f48ca545c9d7da32678488059a79e25dbe7b264e..6dc53cd720155cc280f5606b52b788289e43e115 100644 (file)
@@ -3233,11 +3233,11 @@ discouraged."
 Similar to `call-process-shell-command', but calls `process-file'."
   (declare (advertised-calling-convention
             (command &optional infile buffer display) "24.5"))
-  (process-file
-   (if (file-remote-p default-directory) "/bin/sh" shell-file-name)
-   infile buffer display
-   (if (file-remote-p default-directory) "-c" shell-command-switch)
-   (mapconcat 'identity (cons command args) " ")))
+  ;; On remote hosts, the local `shell-file-name' might be useless.
+  (with-connection-local-variables
+   (process-file
+    shell-file-name infile buffer display shell-command-switch
+    (mapconcat 'identity (cons command args) " "))))
 
 (defun call-shell-region (start end command &optional delete buffer)
   "Send text from START to END as input to an inferior shell running COMMAND.
index bf7cdfafabec0631644c892eaa90bdc806964cd9..34b676ee324a19942cee0592df6c78919aaa2dc8 100644 (file)
@@ -4065,7 +4065,10 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
   "Check `shell-command'."
   :tags '(:expensive-test)
   (skip-unless (tramp--test-enabled))
-  (skip-unless (tramp--test-sh-p))
+  ;; Prior Emacs 27, `shell-file-name' was hard coded as "/bin/sh" for
+  ;; remote processes in Emacs.  That doesn't work for tramp-adb.el.
+  (skip-unless (or (and (tramp--test-adb-p) (tramp--test-emacs27-p))
+                  (tramp--test-sh-p)))
 
   (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil)))
     (let ((tmp-name (tramp--test-make-temp-name nil quoted))
@@ -4093,6 +4096,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
        ;; Cleanup.
        (ignore-errors (delete-file tmp-name)))
 
+      ;; tramp-adb.el is not fit yet for asynchronous processes.
+      (unless (tramp--test-adb-p)
       (unwind-protect
          (with-temp-buffer
            (write-region "foo" nil tmp-name)
@@ -4119,8 +4124,10 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
              (buffer-string))))
 
        ;; Cleanup.
-       (ignore-errors (delete-file tmp-name)))
+       (ignore-errors (delete-file tmp-name))))
 
+      ;; tramp-adb.el is not fit yet for asynchronous processes.
+      (unless (tramp--test-adb-p)
       (unwind-protect
          (with-temp-buffer
            (write-region "foo" nil tmp-name)
@@ -4148,7 +4155,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
              (buffer-string))))
 
        ;; Cleanup.
-       (ignore-errors (delete-file tmp-name))))))
+       (ignore-errors (delete-file tmp-name)))))))
 
 (defun tramp--test-shell-command-to-string-asynchronously (command)
   "Like `shell-command-to-string', but for asynchronous processes."
@@ -5705,6 +5712,9 @@ Since it unloads Tramp, it shall be the last test to run."
 ;;   do not work properly for `nextcloud'.
 ;; * Fix `tramp-test29-start-file-process' and
 ;;   `tramp-test30-make-process' on MS Windows (`process-send-eof'?).
+;; * Fix `tramp-test29-start-file-process',
+;;   `tramp-test30-make-process' and `tramp-test32-shell-command' for
+;;   `adb' (see comment in `tramp-adb-send-command').
 ;; * Fix Bug#16928 in `tramp-test43-asynchronous-requests'.
 
 (provide 'tramp-tests)