]> code.delx.au - gnu-emacs/blob - lisp/net/tramp-adb.el
Merge from emacs-24; up to 2012-12-25T11:37:21Z!dmantipov@yandex.ru
[gnu-emacs] / lisp / net / tramp-adb.el
1 ;;; tramp-adb.el --- Functions for calling Android Debug Bridge from Tramp
2
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
4
5 ;; Author: Juergen Hoetzel <juergen@archlinux.org>
6 ;; Keywords: comm, processes
7 ;; Package: tramp
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; The Android Debug Bridge "adb" must be installed on your local
27 ;; machine. If it is not in your $PATH, add the following form into
28 ;; your .emacs:
29 ;;
30 ;; (setq tramp-adb-program "/path/to/adb")
31 ;;
32 ;; Due to security it is not possible to access non-root devices.
33
34 ;;; Code:
35
36 (require 'tramp)
37 (require 'time-date)
38
39 (defvar dired-move-to-filename-regexp)
40
41 (defcustom tramp-adb-program "adb"
42 "Name of the Android Debug Bridge program."
43 :group 'tramp
44 :version "24.4"
45 :type 'string)
46
47 ;;;###tramp-autoload
48 (defconst tramp-adb-method "adb"
49 "*When this method name is used, forward all calls to Android Debug Bridge.")
50
51 (defcustom tramp-adb-prompt
52 "^\\(?:[[:digit:]]*|?\\)?\\(?:[[:alnum:]]*@[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]"
53 "Regexp used as prompt in almquist shell."
54 :type 'string
55 :version "24.4"
56 :group 'tramp)
57
58 (defconst tramp-adb-ls-date-regexp
59 "[[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]][0-9][0-9]:[0-9][0-9][[:space:]]")
60
61 (defconst tramp-adb-ls-toolbox-regexp
62 (concat
63 "^[[:space:]]*\\([-[:alpha:]]+\\)" ; \1 permissions
64 "[[:space:]]*\\([^[:space:]]+\\)" ; \2 username
65 "[[:space:]]+\\([^[:space:]]+\\)" ; \3 group
66 "[[:space:]]+\\([[:digit:]]+\\)" ; \4 size
67 "[[:space:]]+\\([-[:digit:]]+[[:space:]][:[:digit:]]+\\)" ; \5 date
68 "[[:space:]]+\\(.*\\)$")) ; \6 filename
69
70 ;;;###tramp-autoload
71 (add-to-list 'tramp-methods
72 `(,tramp-adb-method
73 (tramp-tmpdir "/data/local/tmp")))
74
75 ;;;###tramp-autoload
76 (add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil ""))
77
78 ;;;###tramp-autoload
79 (eval-after-load 'tramp
80 '(tramp-set-completion-function
81 tramp-adb-method '((tramp-adb-parse-device-names ""))))
82
83 ;;;###tramp-autoload
84 (add-to-list 'tramp-foreign-file-name-handler-alist
85 (cons 'tramp-adb-file-name-p 'tramp-adb-file-name-handler))
86
87 (defconst tramp-adb-file-name-handler-alist
88 '((directory-file-name . tramp-handle-directory-file-name)
89 (dired-uncache . tramp-handle-dired-uncache)
90 (file-name-as-directory . tramp-handle-file-name-as-directory)
91 (file-name-completion . tramp-handle-file-name-completion)
92 (file-name-all-completions . tramp-adb-handle-file-name-all-completions)
93 (file-attributes . tramp-adb-handle-file-attributes)
94 (file-name-directory . tramp-handle-file-name-directory)
95 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
96 (file-truename . tramp-adb-handle-file-truename)
97 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
98 (file-name-as-directory . tramp-handle-file-name-as-directory)
99 (file-regular-p . tramp-handle-file-regular-p)
100 (file-remote-p . tramp-handle-file-remote-p)
101 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
102 (file-directory-p . tramp-adb-handle-file-directory-p)
103 (file-symlink-p . tramp-handle-file-symlink-p)
104 ;; FIXME: This is too sloppy.
105 (file-executable-p . tramp-handle-file-exists-p)
106 (file-exists-p . tramp-handle-file-exists-p)
107 (file-readable-p . tramp-handle-file-exists-p)
108 (file-writable-p . tramp-adb-handle-file-writable-p)
109 (file-local-copy . tramp-adb-handle-file-local-copy)
110 (file-modes . tramp-handle-file-modes)
111 (expand-file-name . tramp-adb-handle-expand-file-name)
112 (find-backup-file-name . tramp-handle-find-backup-file-name)
113 (directory-files . tramp-handle-directory-files)
114 (directory-files-and-attributes
115 . tramp-adb-handle-directory-files-and-attributes)
116 (make-directory . tramp-adb-handle-make-directory)
117 (delete-directory . tramp-adb-handle-delete-directory)
118 (delete-file . tramp-adb-handle-delete-file)
119 (load . tramp-handle-load)
120 (insert-directory . tramp-adb-handle-insert-directory)
121 (insert-file-contents . tramp-handle-insert-file-contents)
122 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
123 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
124 (vc-registered . ignore) ;no vc control files on Android devices
125 (write-region . tramp-adb-handle-write-region)
126 (set-file-modes . tramp-adb-handle-set-file-modes)
127 (set-file-times . tramp-adb-handle-set-file-times)
128 (copy-file . tramp-adb-handle-copy-file)
129 (rename-file . tramp-adb-handle-rename-file)
130 (process-file . tramp-adb-handle-process-file)
131 (shell-command . tramp-adb-handle-shell-command)
132 (start-file-process . tramp-adb-handle-start-file-process))
133 "Alist of handler functions for Tramp ADB method.")
134
135 ;; It must be a `defsubst' in order to push the whole code into
136 ;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
137 ;;;###tramp-autoload
138 (defsubst tramp-adb-file-name-p (filename)
139 "Check if it's a filename for ADB."
140 (let ((v (tramp-dissect-file-name filename)))
141 (string= (tramp-file-name-method v) tramp-adb-method)))
142
143 ;;;###tramp-autoload
144 (defun tramp-adb-file-name-handler (operation &rest args)
145 "Invoke the ADB handler for OPERATION.
146 First arg specifies the OPERATION, second arg is a list of arguments to
147 pass to the OPERATION."
148 (let ((fn (assoc operation tramp-adb-file-name-handler-alist)))
149 (if fn
150 (save-match-data (apply (cdr fn) args))
151 (tramp-run-real-handler operation args))))
152
153 ;;;###tramp-autoload
154 (defun tramp-adb-parse-device-names (ignore)
155 "Return a list of (nil host) tuples allowed to access."
156 (with-timeout (10)
157 (with-temp-buffer
158 (when (zerop (call-process tramp-adb-program nil t nil "devices"))
159 (let (result)
160 (goto-char (point-min))
161 (while (search-forward-regexp "^\\(\\S-+\\)[[:space:]]+device$" nil t)
162 (add-to-list 'result (list nil (match-string 1))))
163 result)))))
164
165 (defun tramp-adb-handle-expand-file-name (name &optional dir)
166 "Like `expand-file-name' for Tramp files."
167 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
168 (setq dir (or dir default-directory "/"))
169 ;; Unless NAME is absolute, concat DIR and NAME.
170 (unless (file-name-absolute-p name)
171 (setq name (concat (file-name-as-directory dir) name)))
172 ;; If NAME is not a Tramp file, run the real handler.
173 (if (not (tramp-tramp-file-p name))
174 (tramp-run-real-handler 'expand-file-name (list name nil))
175 ;; Dissect NAME.
176 (with-parsed-tramp-file-name name nil
177 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
178 (setq localname (concat "/" localname)))
179 ;; Do normal `expand-file-name' (this does "/./" and "/../").
180 ;; We bind `directory-sep-char' here for XEmacs on Windows,
181 ;; which would otherwise use backslash. `default-directory' is
182 ;; bound, because on Windows there would be problems with UNC
183 ;; shares or Cygwin mounts.
184 (let ((directory-sep-char ?/)
185 (default-directory (tramp-compat-temporary-file-directory)))
186 (tramp-make-tramp-file-name
187 method user host
188 (tramp-drop-volume-letter
189 (tramp-run-real-handler
190 'expand-file-name (list localname))))))))
191
192 (defun tramp-adb-handle-file-directory-p (filename)
193 "Like `file-directory-p' for Tramp files."
194 (car (file-attributes (file-truename filename))))
195
196 ;; This is derived from `tramp-sh-handle-file-truename'. Maybe the
197 ;; code could be shared?
198 (defun tramp-adb-handle-file-truename (filename &optional counter prev-dirs)
199 "Like `file-truename' for Tramp files."
200 (with-parsed-tramp-file-name (expand-file-name filename) nil
201 (with-tramp-file-property v localname "file-truename"
202 (let ((result nil)) ; result steps in reverse order
203 (tramp-message v 4 "Finding true name for `%s'" filename)
204 (let* ((directory-sep-char ?/)
205 (steps (tramp-compat-split-string localname "/"))
206 (localnamedir (tramp-run-real-handler
207 'file-name-as-directory (list localname)))
208 (is-dir (string= localname localnamedir))
209 (thisstep nil)
210 (numchase 0)
211 ;; Don't make the following value larger than
212 ;; necessary. People expect an error message in a
213 ;; timely fashion when something is wrong; otherwise
214 ;; they might think that Emacs is hung. Of course,
215 ;; correctness has to come first.
216 (numchase-limit 20)
217 symlink-target)
218 (while (and steps (< numchase numchase-limit))
219 (setq thisstep (pop steps))
220 (tramp-message
221 v 5 "Check %s"
222 (mapconcat 'identity
223 (append '("") (reverse result) (list thisstep))
224 "/"))
225 (setq symlink-target
226 (nth 0 (file-attributes
227 (tramp-make-tramp-file-name
228 method user host
229 (mapconcat 'identity
230 (append '("")
231 (reverse result)
232 (list thisstep))
233 "/")))))
234 (cond ((string= "." thisstep)
235 (tramp-message v 5 "Ignoring step `.'"))
236 ((string= ".." thisstep)
237 (tramp-message v 5 "Processing step `..'")
238 (pop result))
239 ((stringp symlink-target)
240 ;; It's a symlink, follow it.
241 (tramp-message v 5 "Follow symlink to %s" symlink-target)
242 (setq numchase (1+ numchase))
243 (when (file-name-absolute-p symlink-target)
244 (setq result nil))
245 ;; If the symlink was absolute, we'll get a string
246 ;; like "/user@host:/some/target"; extract the
247 ;; "/some/target" part from it.
248 (when (tramp-tramp-file-p symlink-target)
249 (unless (tramp-equal-remote filename symlink-target)
250 (tramp-error
251 v 'file-error
252 "Symlink target `%s' on wrong host" symlink-target))
253 (setq symlink-target localname))
254 (setq steps
255 (append (tramp-compat-split-string
256 symlink-target "/")
257 steps)))
258 (t
259 ;; It's a file.
260 (setq result (cons thisstep result)))))
261 (when (>= numchase numchase-limit)
262 (tramp-error
263 v 'file-error
264 "Maximum number (%d) of symlinks exceeded" numchase-limit))
265 (setq result (reverse result))
266 ;; Combine list to form string.
267 (setq result
268 (if result
269 (mapconcat 'identity (cons "" result) "/")
270 "/"))
271 (when (and is-dir (or (string= "" result)
272 (not (string= (substring result -1) "/"))))
273 (setq result (concat result "/"))))
274
275 (tramp-message v 4 "True name of `%s' is `%s'" filename result)
276 (tramp-make-tramp-file-name method user host result)))))
277
278 (defun tramp-adb-handle-file-attributes (filename &optional id-format)
279 "Like `file-attributes' for Tramp files."
280 (unless id-format (setq id-format 'integer))
281 (ignore-errors
282 (with-parsed-tramp-file-name filename nil
283 (with-tramp-file-property
284 v localname (format "file-attributes-%s" id-format)
285 (tramp-adb-barf-unless-okay
286 v (format "%s -d -l %s"
287 (tramp-adb-get-ls-command v)
288 (tramp-shell-quote-argument localname)) "")
289 (with-current-buffer (tramp-get-buffer v)
290 (tramp-adb-sh-fix-ls-output)
291 (cdar (tramp-do-parse-file-attributes-with-ls v id-format)))))))
292
293 (defun tramp-do-parse-file-attributes-with-ls (vec &optional id-format)
294 "Parse `file-attributes' for Tramp files using the ls(1) command."
295 (with-current-buffer (tramp-get-buffer vec)
296 (goto-char (point-min))
297 (let ((file-properties nil))
298 (while (re-search-forward tramp-adb-ls-toolbox-regexp nil t)
299 (let* ((mod-string (match-string 1))
300 (is-dir (eq ?d (aref mod-string 0)))
301 (is-symlink (eq ?l (aref mod-string 0)))
302 (uid (match-string 2))
303 (gid (match-string 3))
304 (size (string-to-number (match-string 4)))
305 (date (match-string 5))
306 (name (match-string 6))
307 (symlink-target
308 (and is-symlink
309 (cadr (split-string name "\\( -> \\|\n\\)")))))
310 (push (list
311 (if is-symlink
312 (car (split-string name "\\( -> \\|\n\\)"))
313 name)
314 (or is-dir symlink-target)
315 1 ;link-count
316 ;; no way to handle numeric ids in Androids ash
317 (if (eq id-format 'integer) 0 uid)
318 (if (eq id-format 'integer) 0 gid)
319 '(0 0) ; atime
320 (date-to-time date) ; mtime
321 '(0 0) ; ctime
322 size
323 mod-string
324 ;; fake
325 t 1
326 (tramp-get-device vec))
327 file-properties)))
328 file-properties)))
329
330 (defun tramp-adb-handle-directory-files-and-attributes
331 (directory &optional full match nosort id-format)
332 "Like `directory-files-and-attributes' for Tramp files."
333 (when (file-directory-p directory)
334 (with-parsed-tramp-file-name (expand-file-name directory) nil
335 (with-tramp-file-property
336 v localname (format "directory-files-attributes-%s-%s-%s-%s"
337 full match id-format nosort)
338 (tramp-adb-barf-unless-okay
339 v (format "%s -a -l %s"
340 (tramp-adb-get-ls-command v)
341 (tramp-shell-quote-argument localname)) "")
342 (with-current-buffer (tramp-get-buffer v)
343 (tramp-adb-sh-fix-ls-output)
344 (let ((result (tramp-do-parse-file-attributes-with-ls
345 v (or id-format 'integer))))
346 (when full
347 (setq result
348 (mapcar
349 (lambda (x)
350 (cons (expand-file-name (car x) directory) (cdr x)))
351 result)))
352 (unless nosort
353 (setq result
354 (sort result (lambda (x y) (string< (car x) (car y))))))
355 (delq nil
356 (mapcar (lambda (x)
357 (if (or (not match) (string-match match (car x)))
358 x))
359 result))))))))
360
361 (defun tramp-adb-get-ls-command (vec)
362 (with-tramp-connection-property vec "ls"
363 (tramp-message vec 5 "Finding a suitable `ls' command")
364 (if (zerop (tramp-adb-command-exit-status
365 vec "ls --color=never -al /dev/null"))
366 ;; On CyanogenMod based system BusyBox is used and "ls" output
367 ;; coloring is enabled by default. So we try to disable it
368 ;; when possible.
369 "ls --color=never"
370 "ls")))
371
372 (defun tramp-adb-get-toolbox (vec)
373 "Get shell toolbox implementation: `toolbox' for original distributions
374 or `busybox' for CyanogenMod based distributions"
375 (with-tramp-connection-property vec "toolbox"
376 (tramp-message vec 5 "Checking shell toolbox implementation")
377 (cond
378 ((zerop (tramp-adb-command-exit-status vec "busybox")) 'busybox)
379 ((zerop (tramp-adb-command-exit-status vec "toolbox")) 'toolbox)
380 (t 'unknown))))
381
382 (defun tramp-adb--gnu-switches-to-ash
383 (switches)
384 "Almquist shell can't handle multiple arguments.
385 Convert (\"-al\") to (\"-a\" \"-l\"). Remove arguments like \"--dired\"."
386 (split-string
387 (apply 'concat
388 (mapcar (lambda (s)
389 (replace-regexp-in-string
390 "\\(.\\)" " -\\1"
391 (replace-regexp-in-string "^-" "" s)))
392 ;; FIXME: Warning about removed switches (long and non-dash).
393 (delq nil
394 (mapcar
395 (lambda (s)
396 (and (not (string-match "\\(^--\\|^[^-]\\)" s)) s))
397 switches))))))
398
399 (defun tramp-adb-handle-insert-directory
400 (filename switches &optional wildcard full-directory-p)
401 "Like `insert-directory' for Tramp files."
402 (when (stringp switches)
403 (setq switches (tramp-adb--gnu-switches-to-ash (split-string switches))))
404 (with-parsed-tramp-file-name (file-truename filename) nil
405 (with-current-buffer (tramp-get-buffer v)
406 (let ((name (tramp-shell-quote-argument (directory-file-name localname)))
407 (switch-d (member "-d" switches))
408 (switch-t (member "-t" switches))
409 (switches (mapconcat 'identity (remove "-t" switches) " ")))
410 (tramp-adb-barf-unless-okay
411 v (format "%s %s %s" (tramp-adb-get-ls-command v) switches name)
412 "Cannot insert directory listing: %s" filename)
413 (unless switch-d
414 ;; We insert also filename/. and filename/.., because "ls" doesn't.
415 (narrow-to-region (point) (point))
416 (ignore-errors
417 (tramp-adb-barf-unless-okay
418 v (format "%s -d %s %s %s"
419 (tramp-adb-get-ls-command v)
420 switches
421 (concat (file-name-as-directory name) ".")
422 (concat (file-name-as-directory name) ".."))
423 "Cannot insert directory listing: %s" filename))
424 (widen))
425 (tramp-adb-sh-fix-ls-output switch-t)))
426 (insert-buffer-substring (tramp-get-buffer v))))
427
428 (defun tramp-adb-sh-fix-ls-output (&optional sort-by-time)
429 "Insert dummy 0 in empty size columns.
430 Androids \"ls\" command doesn't insert size column for directories:
431 Emacs dired can't find files."
432 (save-excursion
433 ;; Insert missing size.
434 (goto-char (point-min))
435 (while
436 (search-forward-regexp
437 "[[:space:]]\\([[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]]\\)" nil t)
438 (replace-match "0\\1" "\\1" nil)
439 ;; Insert missing "/".
440 (when (looking-at "[0-9][0-9]:[0-9][0-9][[:space:]]+$")
441 (end-of-line)
442 (insert "/")))
443 ;; Sort entries.
444 (let* ((lines (split-string (buffer-string) "\n" t))
445 (sorted-lines
446 (sort
447 lines
448 (if sort-by-time
449 'tramp-adb-ls-output-time-less-p
450 'tramp-adb-ls-output-name-less-p))))
451 (delete-region (point-min) (point-max))
452 (insert " " (mapconcat 'identity sorted-lines "\n ")))
453 ;; Add final newline.
454 (goto-char (point-max))
455 (unless (= (point) (line-beginning-position))
456 (insert "\n"))))
457
458
459 (defun tramp-adb-ls-output-time-less-p (a b)
460 "Sort \"ls\" output by time, descending."
461 (let (time-a time-b)
462 (string-match tramp-adb-ls-date-regexp a)
463 (setq time-a (apply 'encode-time (parse-time-string (match-string 0 a))))
464 (string-match tramp-adb-ls-date-regexp b)
465 (setq time-b (apply 'encode-time (parse-time-string (match-string 0 b))))
466 (tramp-time-less-p time-b time-a)))
467
468 (defun tramp-adb-ls-output-name-less-p (a b)
469 "Sort \"ls\" output by name, ascending."
470 (let (posa posb)
471 (string-match dired-move-to-filename-regexp a)
472 (setq posa (match-end 0))
473 (string-match dired-move-to-filename-regexp b)
474 (setq posb (match-end 0))
475 (string-lessp (substring a posa) (substring b posb))))
476
477 (defun tramp-adb-handle-make-directory (dir &optional parents)
478 "Like `make-directory' for Tramp files."
479 (setq dir (expand-file-name dir))
480 (with-parsed-tramp-file-name dir nil
481 (when parents
482 (let ((par (expand-file-name ".." dir)))
483 (unless (file-directory-p par)
484 (make-directory par parents))))
485 (tramp-adb-barf-unless-okay
486 v (format "mkdir %s" (tramp-shell-quote-argument localname))
487 "Couldn't make directory %s" dir)
488 (tramp-flush-directory-property v (file-name-directory localname))))
489
490 (defun tramp-adb-handle-delete-directory (directory &optional recursive)
491 "Like `delete-directory' for Tramp files."
492 (setq directory (expand-file-name directory))
493 (with-parsed-tramp-file-name directory nil
494 (tramp-flush-file-property v (file-name-directory localname))
495 (tramp-flush-directory-property v localname)
496 (tramp-adb-barf-unless-okay
497 v (format "%s %s"
498 (if recursive "rm -r" "rmdir")
499 (tramp-shell-quote-argument localname))
500 "Couldn't delete %s" directory)))
501
502 (defun tramp-adb-handle-delete-file (filename &optional trash)
503 "Like `delete-file' for Tramp files."
504 (setq filename (expand-file-name filename))
505 (with-parsed-tramp-file-name filename nil
506 (tramp-flush-file-property v (file-name-directory localname))
507 (tramp-flush-file-property v localname)
508 (tramp-adb-barf-unless-okay
509 v (format "rm %s" (tramp-shell-quote-argument localname))
510 "Couldn't delete %s" filename)))
511
512 (defun tramp-adb-handle-file-name-all-completions (filename directory)
513 "Like `file-name-all-completions' for Tramp files."
514 (all-completions
515 filename
516 (with-parsed-tramp-file-name directory nil
517 (with-tramp-file-property v localname "file-name-all-completions"
518 (save-match-data
519 (tramp-adb-send-command
520 v (format "%s %s"
521 (tramp-adb-get-ls-command v)
522 (tramp-shell-quote-argument localname)))
523 (mapcar
524 (lambda (f)
525 (if (file-directory-p f)
526 (file-name-as-directory f)
527 f))
528 (with-current-buffer (tramp-get-buffer v)
529 (delq
530 nil
531 (mapcar
532 (lambda (l) (and (not (string-match "^[[:space:]]*$" l)) l))
533 (split-string (buffer-string) "\n"))))))))))
534
535 (defun tramp-adb-handle-file-local-copy (filename)
536 "Like `file-local-copy' for Tramp files."
537 (with-parsed-tramp-file-name filename nil
538 (unless (file-exists-p (file-truename filename))
539 (tramp-error
540 v 'file-error
541 "Cannot make local copy of non-existing file `%s'" filename))
542 (let ((tmpfile (tramp-compat-make-temp-file filename)))
543 (with-tramp-progress-reporter
544 v 3 (format "Fetching %s to tmp file %s" filename tmpfile)
545 (when (tramp-adb-execute-adb-command v "pull" localname tmpfile)
546 (delete-file tmpfile)
547 (tramp-error
548 v 'file-error "Cannot make local copy of file `%s'" filename))
549 (set-file-modes tmpfile (file-modes filename)))
550 tmpfile)))
551
552 (defun tramp-adb-handle-file-writable-p (filename)
553 "Like `tramp-sh-handle-file-writable-p'.
554 But handle the case, if the \"test\" command is not available."
555 (with-parsed-tramp-file-name filename nil
556 (with-tramp-file-property v localname "file-writable-p"
557 (if (tramp-adb-find-test-command v)
558 (if (file-exists-p filename)
559 (zerop
560 (tramp-adb-command-exit-status
561 v (format "test -w %s" (tramp-shell-quote-argument localname))))
562 (and
563 (file-directory-p (file-name-directory filename))
564 (file-writable-p (file-name-directory filename))))
565
566 ;; Missing "test" command on Android < 4.
567 (let ((rw-path "/data/data"))
568 (tramp-message
569 v 5
570 "Not implemented yet (assuming \"/data/data\" is writable): %s"
571 localname)
572 (and (>= (length localname) (length rw-path))
573 (string= (substring localname 0 (length rw-path))
574 rw-path)))))))
575
576 (defun tramp-adb-handle-write-region
577 (start end filename &optional append visit lockname confirm)
578 "Like `write-region' for Tramp files."
579 (setq filename (expand-file-name filename))
580 (with-parsed-tramp-file-name filename nil
581 (when append
582 (tramp-error
583 v 'file-error "Cannot append to file using Tramp (`%s')" filename))
584 (when (and confirm (file-exists-p filename))
585 (unless (y-or-n-p (format "File %s exists; overwrite anyway? "
586 filename))
587 (tramp-error v 'file-error "File not overwritten")))
588 ;; We must also flush the cache of the directory, because
589 ;; `file-attributes' reads the values from there.
590 (tramp-flush-file-property v (file-name-directory localname))
591 (tramp-flush-file-property v localname)
592 (let* ((curbuf (current-buffer))
593 (tmpfile (tramp-compat-make-temp-file filename)))
594 (tramp-run-real-handler
595 'write-region
596 (list start end tmpfile append 'no-message lockname confirm))
597 (with-tramp-progress-reporter
598 v 3 (format "Moving tmp file %s to %s" tmpfile filename)
599 (unwind-protect
600 (when (tramp-adb-execute-adb-command v "push" tmpfile localname)
601 (tramp-error v 'file-error "Cannot write: `%s' filename"))
602 (delete-file tmpfile)))
603
604 (unless (equal curbuf (current-buffer))
605 (tramp-error
606 v 'file-error
607 "Buffer has changed from `%s' to `%s'" curbuf (current-buffer))))))
608
609 (defun tramp-adb-handle-set-file-modes (filename mode)
610 "Like `set-file-modes' for Tramp files."
611 (with-parsed-tramp-file-name filename nil
612 (tramp-flush-file-property v localname)
613 (tramp-adb-barf-unless-okay
614 v (format "chmod %s %s" (tramp-compat-decimal-to-octal mode) localname)
615 "Error while changing file's mode %s" filename)))
616
617 (defun tramp-adb-handle-set-file-times (filename &optional time)
618 "Like `set-file-times' for Tramp files."
619 (with-parsed-tramp-file-name filename nil
620 (tramp-flush-file-property v localname)
621 (let ((time (if (or (null time) (equal time '(0 0)))
622 (current-time)
623 time)))
624 (tramp-adb-command-exit-status
625 ;; use shell arithmetic because of Emacs integer size limit
626 v (format "touch -t $(( %d * 65536 + %d )) %s"
627 (car time) (cadr time)
628 (tramp-shell-quote-argument localname))))))
629
630 (defun tramp-adb-handle-copy-file
631 (filename newname &optional ok-if-already-exists keep-date
632 preserve-uid-gid preserve-extended-attributes)
633 "Like `copy-file' for Tramp files.
634 PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
635 (setq filename (expand-file-name filename)
636 newname (expand-file-name newname))
637
638 (if (file-directory-p filename)
639 (tramp-file-name-handler 'copy-directory filename newname keep-date t)
640 (with-tramp-progress-reporter
641 (tramp-dissect-file-name (if (file-remote-p filename) filename newname))
642 0 (format "Copying %s to %s" filename newname)
643
644 (let ((tmpfile (file-local-copy filename)))
645
646 (if tmpfile
647 ;; Remote filename.
648 (condition-case err
649 (rename-file tmpfile newname ok-if-already-exists)
650 ((error quit)
651 (delete-file tmpfile)
652 (signal (car err) (cdr err))))
653
654 ;; Remote newname.
655 (when (file-directory-p newname)
656 (setq newname
657 (expand-file-name (file-name-nondirectory filename) newname)))
658
659 (with-parsed-tramp-file-name newname nil
660 (when (and (not ok-if-already-exists)
661 (file-exists-p newname))
662 (tramp-error v 'file-already-exists newname))
663
664 ;; We must also flush the cache of the directory, because
665 ;; `file-attributes' reads the values from there.
666 (tramp-flush-file-property v (file-name-directory localname))
667 (tramp-flush-file-property v localname)
668 (when (tramp-adb-execute-adb-command v "push" filename localname)
669 (tramp-error
670 v 'file-error "Cannot copy `%s' `%s'" filename newname))))))
671
672 ;; KEEP-DATE handling.
673 (when keep-date
674 (set-file-times newname (nth 5 (file-attributes filename))))))
675
676 (defun tramp-adb-handle-rename-file
677 (filename newname &optional ok-if-already-exists)
678 "Like `rename-file' for Tramp files."
679 (setq filename (expand-file-name filename)
680 newname (expand-file-name newname))
681
682 (with-parsed-tramp-file-name
683 (if (file-remote-p filename) filename newname) nil
684 (with-tramp-progress-reporter
685 v 0 (format "Renaming %s to %s" newname filename)
686
687 (if (and (tramp-equal-remote filename newname)
688 (not (file-directory-p filename)))
689 (progn
690 (when (and (not ok-if-already-exists)
691 (file-exists-p newname))
692 (tramp-error v 'file-already-exists newname))
693 ;; We must also flush the cache of the directory, because
694 ;; `file-attributes' reads the values from there.
695 (tramp-flush-file-property v (file-name-directory localname))
696 (tramp-flush-file-property v localname)
697 ;; Short track.
698 (tramp-adb-barf-unless-okay
699 v (format
700 "mv %s %s"
701 (tramp-file-name-handler 'file-remote-p filename 'localname)
702 localname)
703 "Error renaming %s to %s" filename newname))
704
705 ;; Rename by copy.
706 (copy-file filename newname ok-if-already-exists t t)
707 (delete-file filename)))))
708
709 (defun tramp-adb-handle-process-file
710 (program &optional infile destination display &rest args)
711 "Like `process-file' for Tramp files."
712 ;; The implementation is not complete yet.
713 (when (and (numberp destination) (zerop destination))
714 (error "Implementation does not handle immediate return"))
715
716 (with-parsed-tramp-file-name default-directory nil
717 (let (command input tmpinput stderr tmpstderr outbuf ret)
718 ;; Compute command.
719 (setq command (mapconcat 'tramp-shell-quote-argument
720 (cons program args) " "))
721 ;; Determine input.
722 (if (null infile)
723 (setq input "/dev/null")
724 (setq infile (expand-file-name infile))
725 (if (tramp-equal-remote default-directory infile)
726 ;; INFILE is on the same remote host.
727 (setq input (with-parsed-tramp-file-name infile nil localname))
728 ;; INFILE must be copied to remote host.
729 (setq input (tramp-make-tramp-temp-file v)
730 tmpinput (tramp-make-tramp-file-name method user host input))
731 (copy-file infile tmpinput t)))
732 (when input (setq command (format "%s <%s" command input)))
733
734 ;; Determine output.
735 (cond
736 ;; Just a buffer.
737 ((bufferp destination)
738 (setq outbuf destination))
739 ;; A buffer name.
740 ((stringp destination)
741 (setq outbuf (get-buffer-create destination)))
742 ;; (REAL-DESTINATION ERROR-DESTINATION)
743 ((consp destination)
744 ;; output.
745 (cond
746 ((bufferp (car destination))
747 (setq outbuf (car destination)))
748 ((stringp (car destination))
749 (setq outbuf (get-buffer-create (car destination))))
750 ((car destination)
751 (setq outbuf (current-buffer))))
752 ;; stderr.
753 (cond
754 ((stringp (cadr destination))
755 (setcar (cdr destination) (expand-file-name (cadr destination)))
756 (if (tramp-equal-remote default-directory (cadr destination))
757 ;; stderr is on the same remote host.
758 (setq stderr (with-parsed-tramp-file-name
759 (cadr destination) nil localname))
760 ;; stderr must be copied to remote host. The temporary
761 ;; file must be deleted after execution.
762 (setq stderr (tramp-make-tramp-temp-file v)
763 tmpstderr (tramp-make-tramp-file-name
764 method user host stderr))))
765 ;; stderr to be discarded.
766 ((null (cadr destination))
767 (setq stderr "/dev/null"))))
768 ;; 't
769 (destination
770 (setq outbuf (current-buffer))))
771 (when stderr (setq command (format "%s 2>%s" command stderr)))
772
773 ;; Send the command. It might not return in time, so we protect
774 ;; it. Call it in a subshell, in order to preserve working
775 ;; directory.
776 (condition-case nil
777 (progn
778 (setq ret 0)
779 (tramp-adb-barf-unless-okay
780 v (format "(cd %s; %s)"
781 (tramp-shell-quote-argument localname) command)
782 "")
783 ;; We should show the output anyway.
784 (when outbuf
785 (with-current-buffer outbuf
786 (insert-buffer-substring (tramp-get-connection-buffer v)))
787 (when display (display-buffer outbuf))))
788 ;; When the user did interrupt, we should do it also. We use
789 ;; return code -1 as marker.
790 (quit
791 (kill-buffer (tramp-get-connection-buffer v))
792 (setq ret -1))
793 ;; Handle errors.
794 (error
795 (kill-buffer (tramp-get-connection-buffer v))
796 (setq ret 1)))
797
798 ;; Provide error file.
799 (when tmpstderr (rename-file tmpstderr (cadr destination) t))
800
801 ;; Cleanup. We remove all file cache values for the connection,
802 ;; because the remote process could have changed them.
803 (when tmpinput (delete-file tmpinput))
804
805 ;; `process-file-side-effects' has been introduced with GNU
806 ;; Emacs 23.2. If set to `nil', no remote file will be changed
807 ;; by `program'. If it doesn't exist, we assume its default
808 ;; value 't'.
809 (unless (and (boundp 'process-file-side-effects)
810 (not (symbol-value 'process-file-side-effects)))
811 (tramp-flush-directory-property v ""))
812
813 ;; Return exit status.
814 (if (equal ret -1)
815 (keyboard-quit)
816 ret))))
817
818 (defun tramp-adb-handle-shell-command
819 (command &optional output-buffer error-buffer)
820 "Like `shell-command' for Tramp files."
821 (let* ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command))
822 ;; We cannot use `shell-file-name' and `shell-command-switch',
823 ;; they are variables of the local host.
824 (args (list "sh" "-c" (substring command 0 asynchronous)))
825 current-buffer-p
826 (output-buffer
827 (cond
828 ((bufferp output-buffer) output-buffer)
829 ((stringp output-buffer) (get-buffer-create output-buffer))
830 (output-buffer
831 (setq current-buffer-p t)
832 (current-buffer))
833 (t (get-buffer-create
834 (if asynchronous
835 "*Async Shell Command*"
836 "*Shell Command Output*")))))
837 (error-buffer
838 (cond
839 ((bufferp error-buffer) error-buffer)
840 ((stringp error-buffer) (get-buffer-create error-buffer))))
841 (buffer
842 (if (and (not asynchronous) error-buffer)
843 (with-parsed-tramp-file-name default-directory nil
844 (list output-buffer (tramp-make-tramp-temp-file v)))
845 output-buffer))
846 (p (get-buffer-process output-buffer)))
847
848 ;; Check whether there is another process running. Tramp does not
849 ;; support 2 (asynchronous) processes in parallel.
850 (when p
851 (if (yes-or-no-p "A command is running. Kill it? ")
852 (ignore-errors (kill-process p))
853 (error "Shell command in progress")))
854
855 (if current-buffer-p
856 (progn
857 (barf-if-buffer-read-only)
858 (push-mark nil t))
859 (with-current-buffer output-buffer
860 (setq buffer-read-only nil)
861 (erase-buffer)))
862
863 (if (and (not current-buffer-p) (integerp asynchronous))
864 (prog1
865 ;; Run the process.
866 (apply 'start-file-process "*Async Shell*" buffer args)
867 ;; Display output.
868 (pop-to-buffer output-buffer)
869 (setq mode-line-process '(":%s"))
870 (shell-mode))
871
872 (prog1
873 ;; Run the process.
874 (apply 'process-file (car args) nil buffer nil (cdr args))
875 ;; Insert error messages if they were separated.
876 (when (listp buffer)
877 (with-current-buffer error-buffer
878 (insert-file-contents (cadr buffer)))
879 (delete-file (cadr buffer)))
880 (if current-buffer-p
881 ;; This is like exchange-point-and-mark, but doesn't
882 ;; activate the mark. It is cleaner to avoid activation,
883 ;; even though the command loop would deactivate the mark
884 ;; because we inserted text.
885 (goto-char (prog1 (mark t)
886 (set-marker (mark-marker) (point)
887 (current-buffer))))
888 ;; There's some output, display it.
889 (when (with-current-buffer output-buffer (> (point-max) (point-min)))
890 (if (functionp 'display-message-or-buffer)
891 (tramp-compat-funcall 'display-message-or-buffer output-buffer)
892 (pop-to-buffer output-buffer))))))))
893
894 ;; We use BUFFER also as connection buffer during setup. Because of
895 ;; this, its original contents must be saved, and restored once
896 ;; connection has been setup.
897 (defun tramp-adb-handle-start-file-process (name buffer program &rest args)
898 "Like `start-file-process' for Tramp files."
899 (with-parsed-tramp-file-name default-directory nil
900 ;; When PROGRAM is nil, we should provide a tty. This is not
901 ;; possible here.
902 (unless (stringp program)
903 (tramp-error v 'file-error "PROGRAM must be a string"))
904
905 (let ((command
906 (format "cd %s; %s"
907 (tramp-shell-quote-argument localname)
908 (mapconcat 'tramp-shell-quote-argument
909 (cons program args) " ")))
910 (tramp-process-connection-type
911 (or (null program) tramp-process-connection-type))
912 (bmp (and (buffer-live-p buffer) (buffer-modified-p buffer)))
913 (name1 name)
914 (i 0))
915
916 (unless buffer
917 ;; BUFFER can be nil. We use a temporary buffer.
918 (setq buffer (generate-new-buffer tramp-temp-buffer-name)))
919 (while (get-process name1)
920 ;; NAME must be unique as process name.
921 (setq i (1+ i)
922 name1 (format "%s<%d>" name i)))
923 (setq name name1)
924 ;; Set the new process properties.
925 (tramp-set-connection-property v "process-name" name)
926 (tramp-set-connection-property v "process-buffer" buffer)
927
928 (with-current-buffer (tramp-get-connection-buffer v)
929 (unwind-protect
930 ;; We catch this event. Otherwise, `start-process' could
931 ;; be called on the local host.
932 (save-excursion
933 (save-restriction
934 ;; Activate narrowing in order to save BUFFER
935 ;; contents. Clear also the modification time;
936 ;; otherwise we might be interrupted by
937 ;; `verify-visited-file-modtime'.
938 (let ((buffer-undo-list t)
939 (buffer-read-only nil)
940 (mark (point)))
941 (clear-visited-file-modtime)
942 (narrow-to-region (point-max) (point-max))
943 ;; We call `tramp-adb-maybe-open-connection', in
944 ;; order to cleanup the prompt afterwards.
945 (tramp-adb-maybe-open-connection v)
946 (widen)
947 (delete-region mark (point))
948 (narrow-to-region (point-max) (point-max))
949 ;; Send the command.
950 (let ((tramp-adb-prompt (regexp-quote command)))
951 (tramp-adb-send-command v command))
952 (let ((p (tramp-get-connection-process v)))
953 ;; Set query flag and process marker for this
954 ;; process. We ignore errors, because the process
955 ;; could have finished already.
956 (ignore-errors
957 (tramp-compat-set-process-query-on-exit-flag p t)
958 (set-marker (process-mark p) (point)))
959 ;; Return process.
960 p))))
961
962 ;; Save exit.
963 (if (string-match tramp-temp-buffer-name (buffer-name))
964 (ignore-errors
965 (set-process-buffer (tramp-get-connection-process v) nil)
966 (kill-buffer (current-buffer)))
967 (set-buffer-modified-p bmp))
968 (tramp-set-connection-property v "process-name" nil)
969 (tramp-set-connection-property v "process-buffer" nil))))))
970
971 ;; Helper functions.
972
973 (defun tramp-adb-execute-adb-command (vec &rest args)
974 "Returns nil on success error-output on failure."
975 (when (> (length (tramp-file-name-host vec)) 0)
976 (setq args (append (list "-s" (tramp-file-name-host vec)) args)))
977 (with-temp-buffer
978 (prog1
979 (unless (zerop (apply 'call-process tramp-adb-program nil t nil args))
980 (buffer-string))
981 (tramp-message
982 vec 6 "%s %s\n%s"
983 tramp-adb-program (mapconcat 'identity args " ") (buffer-string)))))
984
985 (defun tramp-adb-find-test-command (vec)
986 "Checks, whether the ash has a builtin \"test\" command.
987 This happens for Android >= 4.0."
988 (with-tramp-connection-property vec "test"
989 (zerop (tramp-adb-command-exit-status vec "type test"))))
990
991 ;; Connection functions
992
993 (defun tramp-adb-send-command (vec command)
994 "Send the COMMAND to connection VEC."
995 (tramp-adb-maybe-open-connection vec)
996 (tramp-message vec 6 "%s" command)
997 (tramp-send-string vec command)
998 ;; fixme: Race condition
999 (tramp-adb-wait-for-output (tramp-get-connection-process vec))
1000 (with-current-buffer (tramp-get-connection-buffer vec)
1001 (save-excursion
1002 (goto-char (point-min))
1003 ;; We can't use stty to disable echo of command.
1004 (delete-matching-lines (regexp-quote command))
1005 ;; When the local machine is W32, there are still trailing ^M.
1006 ;; There must be a better solution by setting the correct coding
1007 ;; system, but this requires changes in core Tramp.
1008 (goto-char (point-min))
1009 (while (re-search-forward "\r+$" nil t)
1010 (replace-match "" nil nil)))))
1011
1012 (defun tramp-adb-command-exit-status
1013 (vec command)
1014 "Run COMMAND and return its exit status.
1015 Sends `echo $?' along with the COMMAND for checking the exit status. If
1016 COMMAND is nil, just sends `echo $?'. Returns the exit status found."
1017 (tramp-adb-send-command
1018 vec (if command
1019 (format "%s; echo tramp_exit_status $?" command)
1020 "echo tramp_exit_status $?"))
1021 (with-current-buffer (tramp-get-connection-buffer vec)
1022 (goto-char (point-max))
1023 (unless (re-search-backward "tramp_exit_status [0-9]+" nil t)
1024 (tramp-error
1025 vec 'file-error "Couldn't find exit status of `%s'" command))
1026 (skip-chars-forward "^ ")
1027 (prog1
1028 (read (current-buffer))
1029 (let (buffer-read-only)
1030 (delete-region (match-beginning 0) (point-max))))))
1031
1032 (defun tramp-adb-barf-unless-okay (vec command fmt &rest args)
1033 "Run COMMAND, check exit status, throw error if exit status not okay.
1034 FMT and ARGS are passed to `error'."
1035 (unless (zerop (tramp-adb-command-exit-status vec command))
1036 (apply 'tramp-error vec 'file-error fmt args)))
1037
1038 (defun tramp-adb-wait-for-output (proc &optional timeout)
1039 "Wait for output from remote command."
1040 (unless (buffer-live-p (process-buffer proc))
1041 (delete-process proc)
1042 (tramp-error proc 'file-error "Process `%s' not available, try again" proc))
1043 (with-current-buffer (process-buffer proc)
1044 (if (tramp-wait-for-regexp proc timeout tramp-adb-prompt)
1045 (let (buffer-read-only)
1046 (goto-char (point-min))
1047 ;; ADB terminal sends "^H" sequences.
1048 (when (re-search-forward "<\b+" (point-at-eol) t)
1049 (forward-line 1)
1050 (delete-region (point-min) (point)))
1051 ;; Delete the prompt.
1052 (goto-char (point-min))
1053 (when (re-search-forward tramp-adb-prompt (point-at-eol) t)
1054 (forward-line 1)
1055 (delete-region (point-min) (point)))
1056 (goto-char (point-max))
1057 (re-search-backward tramp-adb-prompt nil t)
1058 (delete-region (point) (point-max)))
1059 (if timeout
1060 (tramp-error
1061 proc 'file-error
1062 "[[Remote adb prompt `%s' not found in %d secs]]"
1063 tramp-adb-prompt timeout)
1064 (tramp-error
1065 proc 'file-error
1066 "[[Remote prompt `%s' not found]]" tramp-adb-prompt)))))
1067
1068 (defun tramp-adb-maybe-open-connection (vec)
1069 "Maybe open a connection VEC.
1070 Does not do anything if a connection is already open, but re-opens the
1071 connection if a previous connection has died for some reason."
1072 (let* ((buf (tramp-get-connection-buffer vec))
1073 (p (get-buffer-process buf))
1074 (host (tramp-file-name-host vec))
1075 (user (tramp-file-name-user vec))
1076 (devices (mapcar 'cadr (tramp-adb-parse-device-names nil))))
1077
1078 ;; Maybe we know already that "su" is not supported. We cannot
1079 ;; use a connection property, because we have not checked yet
1080 ;; whether it is still the same device.
1081 (when (and user (not (tramp-get-file-property vec "" "su-command-p" t)))
1082 (tramp-error vec 'file-error "Cannot switch to user `%s'" user))
1083
1084 (unless
1085 (and p (processp p) (memq (process-status p) '(run open)))
1086 (save-match-data
1087 (when (and p (processp p)) (delete-process p))
1088 (if (not devices)
1089 (tramp-error vec 'file-error "No device connected"))
1090 (if (and (> (length host) 0) (not (member host devices)))
1091 (tramp-error vec 'file-error "Device %s not connected" host))
1092 (if (and (> (length devices) 1) (zerop (length host)))
1093 (tramp-error
1094 vec 'file-error
1095 "Multiple Devices connected: No Host/Device specified"))
1096 (with-tramp-progress-reporter vec 3 "Opening adb shell connection"
1097 (let* ((coding-system-for-read 'utf-8-dos) ;is this correct?
1098 (process-connection-type tramp-process-connection-type)
1099 (args (if (> (length host) 0)
1100 (list "-s" host "shell")
1101 (list "shell")))
1102 (p (let ((default-directory
1103 (tramp-compat-temporary-file-directory)))
1104 (apply 'start-process (tramp-get-connection-name vec) buf
1105 tramp-adb-program args))))
1106 (tramp-message
1107 vec 6 "%s" (mapconcat 'identity (process-command p) " "))
1108 ;; Wait for initial prompt.
1109 (tramp-adb-wait-for-output p 30)
1110 (unless (eq 'run (process-status p))
1111 (tramp-error vec 'file-error "Terminated!"))
1112 (tramp-compat-set-process-query-on-exit-flag p nil)
1113
1114 ;; Check whether the properties have been changed. If
1115 ;; yes, this is a strong indication that we must expire all
1116 ;; connection properties. We start again.
1117 (tramp-message vec 5 "Checking system information")
1118 (tramp-adb-send-command
1119 vec "echo \\\"`getprop ro.product.model` `getprop ro.product.version` `getprop ro.build.version.release`\\\"")
1120 (let ((old-getprop
1121 (tramp-get-connection-property vec "getprop" nil))
1122 (new-getprop
1123 (tramp-set-connection-property
1124 vec "getprop"
1125 (with-current-buffer (tramp-get-connection-buffer vec)
1126 ;; Read the expression.
1127 (goto-char (point-min))
1128 (read (current-buffer))))))
1129 (when (and (stringp old-getprop)
1130 (not (string-equal old-getprop new-getprop)))
1131 (tramp-cleanup vec)
1132 (tramp-message
1133 vec 3
1134 "Connection reset, because remote host changed from `%s' to `%s'"
1135 old-getprop new-getprop)
1136 (tramp-adb-maybe-open-connection vec)))
1137
1138 ;; Change user if indicated.
1139 (when user
1140 (tramp-adb-send-command vec (format "su %s" user))
1141 (unless (zerop (tramp-adb-command-exit-status vec nil))
1142 (delete-process p)
1143 (tramp-set-file-property vec "" "su-command-p" nil)
1144 (tramp-error
1145 vec 'file-error "Cannot switch to user `%s'" user)))
1146
1147 ;; Set "remote-path" connection property. This is needed
1148 ;; for eshell.
1149 (tramp-adb-send-command vec "echo \\\"$PATH\\\"")
1150 (tramp-set-connection-property
1151 vec "remote-path"
1152 (split-string
1153 (with-current-buffer (tramp-get-connection-buffer vec)
1154 ;; Read the expression.
1155 (goto-char (point-min))
1156 (read (current-buffer)))
1157 ":" 'omit-nulls))))))))
1158
1159 (provide 'tramp-adb)
1160 ;;; tramp-adb.el ends here