]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix last change in tramp-adb-handle-make-process
authorMichael Albinus <michael.albinus@gmx.de>
Sun, 19 Jun 2022 19:07:29 +0000 (21:07 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Sun, 19 Jun 2022 19:07:29 +0000 (21:07 +0200)
* lisp/net/tramp-adb.el (tramp-adb-handle-make-process):
Fix process buffer management.

lisp/net/tramp-adb.el

index 0c3d87cc91947d5e2baeeb23dc99af051a1b0d23..ebcdf00c488ba14fcf5544ec7e71eaa144101d97 100644 (file)
@@ -955,18 +955,18 @@ implementation will be used."
                    name1 (format "%s<%d>" name i)))
            (setq name name1)
 
-           (with-current-buffer (tramp-get-connection-buffer v)
-             (unwind-protect
-                 ;; We catch this event.  Otherwise, `make-process'
-                 ;; could be called on the local host.
-                 (save-excursion
-                   (save-restriction
-                     (with-tramp-saved-connection-property v "process-name"
-                       (with-tramp-saved-connection-property v "process-buffer"
-                         ;; Set the new process properties.
-                         (tramp-set-connection-property v "process-name" name)
-                         (tramp-set-connection-property
-                          v "process-buffer" buffer)
+           (with-tramp-saved-connection-property v "process-name"
+             (with-tramp-saved-connection-property v "process-buffer"
+               ;; Set the new process properties.
+               (tramp-set-connection-property v "process-name" name)
+               (tramp-set-connection-property v "process-buffer" buffer)
+               (with-current-buffer (tramp-get-connection-buffer v)
+                 (unwind-protect
+                     ;; We catch this event.  Otherwise,
+                     ;; `make-process' could be called on the local
+                     ;; host.
+                     (save-excursion
+                       (save-restriction
                          ;; Activate narrowing in order to save
                          ;; BUFFER contents.  Clear also the
                          ;; modification time; otherwise we might be
@@ -980,8 +980,7 @@ implementation will be used."
                            (clear-visited-file-modtime)
                            (narrow-to-region (point-max) (point-max))
                            ;; We call `tramp-adb-maybe-open-connection',
-                           ;; in order to cleanup the prompt
-                           ;; afterwards.
+                           ;; in order to cleanup the prompt afterwards.
                            (tramp-adb-maybe-open-connection v)
                            (delete-region (point-min) (point-max))
                            ;; Send the command.
@@ -1001,55 +1000,58 @@ implementation will be used."
                            ;; already.
                            (ignore-errors
                              (set-process-query-on-exit-flag p (null noquery))
-                             (set-marker (process-mark p) (point))))
-
-                         ;; Copy tmpstderr file.  "process-buffer"
-                         ;; and "process-name" must be reset already;
-                         ;; otherwise `rename-file', `delete-file' or
-                         ;; `insert-file-contents' will fail.
-                         (when (and (stringp stderr)
-                                    (not (tramp-tramp-file-p stderr)))
-                           (add-function
-                            :after (process-sentinel p)
-                            (lambda (_proc _msg)
-                              (rename-file remote-tmpstderr stderr))))
-                         ;; Read initial output.  Remove the first
-                         ;; line, which is the command echo.
-                         (unless (eq filter t)
-                           (while
-                               (progn
-                                 (goto-char (point-min))
-                                 (not (re-search-forward "[\n]" nil t)))
-                             (tramp-accept-process-output p 0))
-                           (delete-region (point-min) (point)))
-                         ;; Provide error buffer.  This shows only
-                         ;; initial error messages; messages arriving
-                         ;; later on will be inserted when the
-                         ;; process is deleted.  The temporary file
-                         ;; will exist until the process is deleted.
-                         (when (bufferp stderr)
-                           (with-current-buffer stderr
-                             (insert-file-contents-literally
-                              remote-tmpstderr 'visit))
-                           ;; Delete tmpstderr file.
-                           (add-function
-                            :after (process-sentinel p)
-                            (lambda (_proc _msg)
-                              (with-current-buffer stderr
-                                (insert-file-contents-literally
-                                 remote-tmpstderr 'visit nil nil 'replace))
-                              (delete-file remote-tmpstderr))))
-                         ;; Return process.
-                         p))))
-
-               ;; Save exit.
-               ;; FIXME: Does `tramp-get-connection-process' return
-               ;; the proper value?
-               (if (string-prefix-p tramp-temp-buffer-name (buffer-name))
-                   (ignore-errors
-                     (set-process-buffer (tramp-get-connection-process v) nil)
-                     (kill-buffer (current-buffer)))
-                 (set-buffer-modified-p bmp))))))))))
+                             (set-marker (process-mark p) (point))
+                             ;; We must flush them here already;
+                             ;; otherwise `rename-file', `delete-file' or
+                             ;; `insert-file-contents' will fail.
+                             (tramp-flush-connection-property v "process-name")
+                             (tramp-flush-connection-property
+                              v "process-buffer")
+                             ;; Copy tmpstderr file.
+                             (when (and (stringp stderr)
+                                        (not (tramp-tramp-file-p stderr)))
+                               (add-function
+                                :after (process-sentinel p)
+                                (lambda (_proc _msg)
+                                  (rename-file remote-tmpstderr stderr))))
+                             ;; Read initial output.  Remove the
+                             ;; first line, which is the command
+                             ;; echo.
+                             (unless (eq filter t)
+                               (while
+                                   (progn
+                                     (goto-char (point-min))
+                                     (not (re-search-forward "[\n]" nil t)))
+                                 (tramp-accept-process-output p 0))
+                               (delete-region (point-min) (point)))
+                             ;; Provide error buffer.  This shows
+                             ;; only initial error messages; messages
+                             ;; arriving later on will be inserted
+                             ;; when the process is deleted.  The
+                             ;; temporary file will exist until the
+                             ;; process is deleted.
+                             (when (bufferp stderr)
+                               (with-current-buffer stderr
+                                 (insert-file-contents-literally
+                                  remote-tmpstderr 'visit))
+                               ;; Delete tmpstderr file.
+                               (add-function
+                                :after (process-sentinel p)
+                                (lambda (_proc _msg)
+                                  (with-current-buffer stderr
+                                    (insert-file-contents-literally
+                                     remote-tmpstderr 'visit nil nil 'replace))
+                                  (delete-file remote-tmpstderr))))
+                             ;; Return process.
+                             p))))
+
+                   ;; Save exit.
+                   (if (string-prefix-p tramp-temp-buffer-name (buffer-name))
+                       (ignore-errors
+                         (set-process-buffer
+                          (tramp-get-connection-process v) nil)
+                         (kill-buffer (current-buffer)))
+                     (set-buffer-modified-p bmp))))))))))))
 
 (defun tramp-adb-handle-exec-path ()
   "Like `exec-path' for Tramp files."