diff options
| -rw-r--r-- | lisp/net/tramp-adb.el | 145 |
1 files changed, 35 insertions, 110 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index b40e69ef634..33ff4ccacee 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el | |||
| @@ -78,8 +78,11 @@ It is used for TCP/IP devices." | |||
| 78 | (tramp--with-startup | 78 | (tramp--with-startup |
| 79 | (add-to-list 'tramp-methods | 79 | (add-to-list 'tramp-methods |
| 80 | `(,tramp-adb-method | 80 | `(,tramp-adb-method |
| 81 | (tramp-tmpdir "/data/local/tmp") | 81 | ;; Used in `tramp-handle-shell-command'. |
| 82 | (tramp-default-port 5555))) | 82 | (tramp-remote-shell "/system/bin/sh") |
| 83 | (tramp-remote-shell-args ("-c")) | ||
| 84 | (tramp-tmpdir "/data/local/tmp") | ||
| 85 | (tramp-default-port 5555))) | ||
| 83 | 86 | ||
| 84 | (add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil "")) | 87 | (add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil "")) |
| 85 | 88 | ||
| @@ -153,7 +156,7 @@ It is used for TCP/IP devices." | |||
| 153 | (set-file-selinux-context . ignore) | 156 | (set-file-selinux-context . ignore) |
| 154 | (set-file-times . tramp-adb-handle-set-file-times) | 157 | (set-file-times . tramp-adb-handle-set-file-times) |
| 155 | (set-visited-file-modtime . tramp-handle-set-visited-file-modtime) | 158 | (set-visited-file-modtime . tramp-handle-set-visited-file-modtime) |
| 156 | (shell-command . tramp-adb-handle-shell-command) | 159 | (shell-command . tramp-handle-shell-command) |
| 157 | (start-file-process . tramp-handle-start-file-process) | 160 | (start-file-process . tramp-handle-start-file-process) |
| 158 | (substitute-in-file-name . tramp-handle-substitute-in-file-name) | 161 | (substitute-in-file-name . tramp-handle-substitute-in-file-name) |
| 159 | (temporary-file-directory . tramp-handle-temporary-file-directory) | 162 | (temporary-file-directory . tramp-handle-temporary-file-directory) |
| @@ -922,80 +925,6 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 922 | (keyboard-quit) | 925 | (keyboard-quit) |
| 923 | ret)))) | 926 | ret)))) |
| 924 | 927 | ||
| 925 | (defun tramp-adb-handle-shell-command | ||
| 926 | (command &optional output-buffer error-buffer) | ||
| 927 | "Like `shell-command' for Tramp files." | ||
| 928 | (let* ((asynchronous (string-match-p "[ \t]*&[ \t]*\\'" command)) | ||
| 929 | ;; We cannot use `shell-file-name' and `shell-command-switch', | ||
| 930 | ;; they are variables of the local host. | ||
| 931 | (args (list "sh" "-c" (substring command 0 asynchronous))) | ||
| 932 | current-buffer-p | ||
| 933 | (output-buffer | ||
| 934 | (cond | ||
| 935 | ((bufferp output-buffer) output-buffer) | ||
| 936 | ((stringp output-buffer) (get-buffer-create output-buffer)) | ||
| 937 | (output-buffer | ||
| 938 | (setq current-buffer-p t) | ||
| 939 | (current-buffer)) | ||
| 940 | (t (get-buffer-create | ||
| 941 | (if asynchronous | ||
| 942 | "*Async Shell Command*" | ||
| 943 | "*Shell Command Output*"))))) | ||
| 944 | (error-buffer | ||
| 945 | (cond | ||
| 946 | ((bufferp error-buffer) error-buffer) | ||
| 947 | ((stringp error-buffer) (get-buffer-create error-buffer)))) | ||
| 948 | (buffer | ||
| 949 | (if (and (not asynchronous) error-buffer) | ||
| 950 | (with-parsed-tramp-file-name default-directory nil | ||
| 951 | (list output-buffer (tramp-make-tramp-temp-file v))) | ||
| 952 | output-buffer)) | ||
| 953 | (p (get-buffer-process output-buffer))) | ||
| 954 | |||
| 955 | ;; Check whether there is another process running. Tramp does not | ||
| 956 | ;; support 2 (asynchronous) processes in parallel. | ||
| 957 | (when p | ||
| 958 | (if (yes-or-no-p "A command is running. Kill it? ") | ||
| 959 | (ignore-errors (kill-process p)) | ||
| 960 | (tramp-user-error p "Shell command in progress"))) | ||
| 961 | |||
| 962 | (if current-buffer-p | ||
| 963 | (progn | ||
| 964 | (barf-if-buffer-read-only) | ||
| 965 | (push-mark nil t)) | ||
| 966 | (with-current-buffer output-buffer | ||
| 967 | (setq buffer-read-only nil) | ||
| 968 | (erase-buffer))) | ||
| 969 | |||
| 970 | (if (and (not current-buffer-p) (integerp asynchronous)) | ||
| 971 | (prog1 | ||
| 972 | ;; Run the process. | ||
| 973 | (apply #'start-file-process "*Async Shell*" buffer args) | ||
| 974 | ;; Display output. | ||
| 975 | (pop-to-buffer output-buffer) | ||
| 976 | (setq mode-line-process '(":%s")) | ||
| 977 | (shell-mode)) | ||
| 978 | |||
| 979 | (prog1 | ||
| 980 | ;; Run the process. | ||
| 981 | (apply #'process-file (car args) nil buffer nil (cdr args)) | ||
| 982 | ;; Insert error messages if they were separated. | ||
| 983 | (when (listp buffer) | ||
| 984 | (with-current-buffer error-buffer | ||
| 985 | (insert-file-contents (cadr buffer))) | ||
| 986 | (delete-file (cadr buffer))) | ||
| 987 | (if current-buffer-p | ||
| 988 | ;; This is like exchange-point-and-mark, but doesn't | ||
| 989 | ;; activate the mark. It is cleaner to avoid activation, | ||
| 990 | ;; even though the command loop would deactivate the mark | ||
| 991 | ;; because we inserted text. | ||
| 992 | (goto-char (prog1 (mark t) | ||
| 993 | (set-marker (mark-marker) (point) | ||
| 994 | (current-buffer)))) | ||
| 995 | ;; There's some output, display it. | ||
| 996 | (when (with-current-buffer output-buffer (> (point-max) (point-min))) | ||
| 997 | (display-message-or-buffer output-buffer))))))) | ||
| 998 | |||
| 999 | ;; We use BUFFER also as connection buffer during setup. Because of | 928 | ;; We use BUFFER also as connection buffer during setup. Because of |
| 1000 | ;; this, its original contents must be saved, and restored once | 929 | ;; this, its original contents must be saved, and restored once |
| 1001 | ;; connection has been setup. | 930 | ;; connection has been setup. |
| @@ -1085,9 +1014,13 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 1085 | (delete-region mark (point)) | 1014 | (delete-region mark (point)) |
| 1086 | (narrow-to-region (point-max) (point-max)) | 1015 | (narrow-to-region (point-max) (point-max)) |
| 1087 | ;; Send the command. | 1016 | ;; Send the command. |
| 1088 | (let ((tramp-adb-prompt (regexp-quote command))) | 1017 | (let* ((p (tramp-get-connection-process v)) |
| 1089 | (tramp-adb-send-command v command)) | 1018 | (prompt |
| 1090 | (let ((p (tramp-get-connection-process v))) | 1019 | (tramp-get-connection-property p "prompt" nil))) |
| 1020 | (tramp-set-connection-property | ||
| 1021 | p "prompt" (regexp-quote command)) | ||
| 1022 | (tramp-adb-send-command v command) | ||
| 1023 | (tramp-set-connection-property p "prompt" prompt) | ||
| 1091 | ;; Stop process if indicated. | 1024 | ;; Stop process if indicated. |
| 1092 | (when stop | 1025 | (when stop |
| 1093 | (stop-process p)) | 1026 | (stop-process p)) |
| @@ -1239,37 +1172,29 @@ FMT and ARGS are passed to `error'." | |||
| 1239 | (unless (buffer-live-p (process-buffer proc)) | 1172 | (unless (buffer-live-p (process-buffer proc)) |
| 1240 | (delete-process proc) | 1173 | (delete-process proc) |
| 1241 | (tramp-error proc 'file-error "Process `%s' not available, try again" proc)) | 1174 | (tramp-error proc 'file-error "Process `%s' not available, try again" proc)) |
| 1242 | (with-current-buffer (process-buffer proc) | 1175 | (let ((prompt (tramp-get-connection-property proc "prompt" tramp-adb-prompt))) |
| 1243 | (if (tramp-wait-for-regexp | 1176 | (with-current-buffer (process-buffer proc) |
| 1244 | proc timeout | 1177 | (if (tramp-wait-for-regexp proc timeout prompt) |
| 1245 | (tramp-get-connection-property proc "prompt" tramp-adb-prompt)) | 1178 | (let ((inhibit-read-only t)) |
| 1246 | (let ((inhibit-read-only t)) | 1179 | (goto-char (point-min)) |
| 1247 | (goto-char (point-min)) | 1180 | ;; ADB terminal sends "^H" sequences. |
| 1248 | ;; ADB terminal sends "^H" sequences. | 1181 | (when (re-search-forward "<\b+" (point-at-eol) t) |
| 1249 | (when (re-search-forward "<\b+" (point-at-eol) t) | 1182 | (forward-line 1) |
| 1250 | (forward-line 1) | 1183 | (delete-region (point-min) (point))) |
| 1251 | (delete-region (point-min) (point))) | 1184 | ;; Delete the prompt. |
| 1252 | ;; Delete the prompt. | 1185 | (goto-char (point-min)) |
| 1253 | (goto-char (point-min)) | 1186 | (when (re-search-forward prompt (point-at-eol) t) |
| 1254 | (when (re-search-forward | 1187 | (forward-line 1) |
| 1255 | (tramp-get-connection-property proc "prompt" tramp-adb-prompt) | 1188 | (delete-region (point-min) (point))) |
| 1256 | (point-at-eol) t) | 1189 | (goto-char (point-max)) |
| 1257 | (forward-line 1) | 1190 | (re-search-backward prompt nil t) |
| 1258 | (delete-region (point-min) (point))) | 1191 | (delete-region (point) (point-max))) |
| 1259 | (goto-char (point-max)) | 1192 | (if timeout |
| 1260 | (re-search-backward | 1193 | (tramp-error |
| 1261 | (tramp-get-connection-property proc "prompt" tramp-adb-prompt) nil t) | 1194 | proc 'file-error |
| 1262 | (delete-region (point) (point-max))) | 1195 | "[[Remote prompt `%s' not found in %d secs]]" prompt timeout) |
| 1263 | (if timeout | ||
| 1264 | (tramp-error | 1196 | (tramp-error |
| 1265 | proc 'file-error | 1197 | proc 'file-error "[[Remote prompt `%s' not found]]" prompt)))))) |
| 1266 | "[[Remote adb prompt `%s' not found in %d secs]]" | ||
| 1267 | (tramp-get-connection-property proc "prompt" tramp-adb-prompt) | ||
| 1268 | timeout) | ||
| 1269 | (tramp-error | ||
| 1270 | proc 'file-error | ||
| 1271 | "[[Remote prompt `%s' not found]]" | ||
| 1272 | (tramp-get-connection-property proc "prompt" tramp-adb-prompt)))))) | ||
| 1273 | 1198 | ||
| 1274 | (defun tramp-adb-maybe-open-connection (vec) | 1199 | (defun tramp-adb-maybe-open-connection (vec) |
| 1275 | "Maybe open a connection VEC. | 1200 | "Maybe open a connection VEC. |