Jürgen Hötzel <[email protected]> writes: > Hi Michael,
Hi Juergen, I've prepared the next patch set. Most visible might be patches 0005 and 0006, which allow use of several devices in parallel. Next I will work on copy-file and rename-file. Afterwards, maybe I will have a look on calling processes on a device. > Jürgen Best regards, Michael.
>From 919772d295d2974d035ee6b9785f67f7f49ead4d Mon Sep 17 00:00:00 2001 From: Michael Albinus <[email protected]> Date: Fri, 27 May 2011 22:41:25 +0200 Subject: [PATCH 1/6] Introduce `tramp-adb-barf-unless-okay'. Use it instead of `tramp-barf-unless-okay'. --- tramp-adb.el | 47 +++++++++++++++++++++++++++++------------------ 1 files changed, 29 insertions(+), 18 deletions(-) diff --git a/tramp-adb.el b/tramp-adb.el index a9d8026..d4b2086 100644 --- a/tramp-adb.el +++ b/tramp-adb.el @@ -229,8 +229,7 @@ pass to the OPERATION." (with-parsed-tramp-file-name filename nil (with-file-property v localname (format "file-attributes-%s" id-format) (tramp-adb-send-command - v - (format "ls -d -l %s" (tramp-shell-quote-argument localname))) + v (format "ls -d -l %s" (tramp-shell-quote-argument localname))) (with-current-buffer (tramp-get-buffer v) (unless (string-match tramp-adb-ls-errors (buffer-string)) (tramp-adb-sh-fix-ls-output) @@ -345,14 +344,12 @@ pass to the OPERATION." (setq dir (expand-file-name dir)) (with-parsed-tramp-file-name dir nil (when parents - (tramp-message v 5 "mkdir doesn't handle \"-p\" switch: mkdir \"%s\"" (tramp-shell-quote-argument localname))) - (save-excursion - (tramp-barf-unless-okay - v (format "%s %s" - "mkdir" - (tramp-shell-quote-argument localname)) - "Couldn't make directory %s" dir) - (tramp-flush-directory-property v (file-name-directory localname))))) + (tramp-message + v 5 "mkdir doesn't handle \"-p\" switch: mkdir \"%s\"" localname)) + (tramp-adb-barf-unless-okay + v (format "mkdir %s" (tramp-shell-quote-argument localname)) + "Couldn't make directory %s" dir) + (tramp-flush-directory-property v (file-name-directory localname)))) (defun tramp-adb-handle-delete-directory (directory &optional recursive) "Like `delete-directory' for Tramp files." @@ -360,7 +357,7 @@ pass to the OPERATION." (with-parsed-tramp-file-name directory nil (tramp-flush-file-property v (file-name-directory localname)) (tramp-flush-directory-property v localname) - (tramp-barf-unless-okay + (tramp-adb-barf-unless-okay v (format "%s %s" (if recursive "rm -r" "rmdir") (tramp-shell-quote-argument localname)) @@ -372,10 +369,8 @@ pass to the OPERATION." (with-parsed-tramp-file-name filename nil (tramp-flush-file-property v (file-name-directory localname)) (tramp-flush-file-property v localname) - (tramp-barf-unless-okay - v (format "%s %s" - (or (and trash (tramp-get-remote-trash v)) "rm") - (tramp-shell-quote-argument localname)) + (tramp-adb-barf-unless-okay + v (format "rm %s" (tramp-shell-quote-argument localname)) "Couldn't delete %s" filename))) (defun tramp-adb-handle-file-name-all-completions (filename directory) @@ -477,8 +472,7 @@ pass to the OPERATION." ;; Connection functions (defun tramp-adb-send-command (vec command) - "Send the COMMAND to connection VEC. -Returns nil if there has been an error message from adb." + "Send the COMMAND to connection VEC." (tramp-adb-maybe-open-connection vec) (tramp-message vec 6 "%s" command) (tramp-send-string vec command) @@ -492,7 +486,24 @@ Returns nil if there has been an error message from adb." ;; When the local machine is W32, there are still trailing ^M. ;; There must be a better solution by setting the correct coding ;; system, but this requires changes in core Tramp. - (replace-regexp "\r+$" "" nil (point-min) (point-max))))) + (goto-char (point-min)) + (while (re-search-forward "\r+$" nil t) + (replace-match "" nil nil))))) + +(defun tramp-adb-barf-unless-okay (vec command fmt &rest args) + "Run COMMAND, check exit status, throw error if exit status not okay. +FMT and ARGS are passed to `error'." + (tramp-adb-send-command vec (format "%s; echo tramp_exit_status $?" command)) + (with-current-buffer (tramp-get-connection-buffer vec) + (goto-char (point-max)) + (unless (re-search-backward "tramp_exit_status [0-9]+" nil t) + (tramp-error + vec 'file-error "Couldn't find exit status of `%s'" command)) + (skip-chars-forward "^ ") + (unless (zerop (read (current-buffer))) + (apply 'tramp-error vec 'file-error fmt args)) + (let (buffer-read-only) + (delete-region (match-beginning 0) (point-max))))) (defun tramp-adb-wait-for-output (proc &optional timeout) "Wait for output from remote command." -- 1.7.4.1
>From 211732d145cf7eca35cca938163f3b445ec91a51 Mon Sep 17 00:00:00 2001 From: Michael Albinus <[email protected]> Date: Fri, 27 May 2011 22:47:04 +0200 Subject: [PATCH 2/6] Handle "/./" and "/../" in `tramp-adb-handle-expand-file-name'. --- tramp-adb.el | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tramp-adb.el b/tramp-adb.el index d4b2086..504f7ca 100644 --- a/tramp-adb.el +++ b/tramp-adb.el @@ -129,9 +129,18 @@ pass to the OPERATION." (with-parsed-tramp-file-name name nil (unless (tramp-run-real-handler 'file-name-absolute-p (list localname)) (setq localname (concat "/" localname))) - (let ((r (tramp-make-tramp-file-name "adb" nil nil localname ))) - (tramp-message v 5 "%s -> %s" name r) - r)))) + ;; Do normal `expand-file-name' (this does "/./" and "/../"). + ;; We bind `directory-sep-char' here for XEmacs on Windows, + ;; which would otherwise use backslash. `default-directory' is + ;; bound, because on Windows there would be problems with UNC + ;; shares or Cygwin mounts. + (let ((directory-sep-char ?/) + (default-directory (tramp-compat-temporary-file-directory))) + (tramp-make-tramp-file-name + method user host + (tramp-drop-volume-letter + (tramp-run-real-handler + 'expand-file-name (list localname)))))))) (defun tramp-adb-handle-file-directory-p (filename) "Like `file-directory-p' for Tramp files." @@ -272,7 +281,6 @@ pass to the OPERATION." "Like `insert-directory' for Tramp files." (when (stringp switches) (setq switches (tramp-adb--gnu-switches-to-ash (split-string switches)))) - ;; FIXME: tramp-adb-handle-expand-file-name does not handle name/. and name/.. (with-parsed-tramp-file-name (expand-file-name filename) nil (let ((cmd (format "ls %s " (mapconcat 'identity (remove "-t" switches) " "))) -- 1.7.4.1
>From 25ac4c7bc004b829a1d754b76439464dea5fbb4e Mon Sep 17 00:00:00 2001 From: Michael Albinus <[email protected]> Date: Fri, 27 May 2011 22:54:25 +0200 Subject: [PATCH 3/6] Don't call `tramp-adb-handle-*' functions directly. --- tramp-adb.el | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-) diff --git a/tramp-adb.el b/tramp-adb.el index 504f7ca..74ce588 100644 --- a/tramp-adb.el +++ b/tramp-adb.el @@ -144,11 +144,10 @@ pass to the OPERATION." (defun tramp-adb-handle-file-directory-p (filename) "Like `file-directory-p' for Tramp files." - (let (symlink (file-symlink-p filename)) - (if symlink - (tramp-adb-handle-file-directory-p symlink) - (and (file-exists-p filename) - (car (file-attributes filename)))))) + (let ((symlink (file-symlink-p filename))) + (if (stringp symlink) + (file-directory-p symlink) + (car (file-attributes filename))))) ;; This is derived from `tramp-sh-handle-file-truename'. Maybe the ;; code could be shared? @@ -340,9 +339,7 @@ pass to the OPERATION." "Like `directory-files' for Tramp files." (with-parsed-tramp-file-name dir nil (tramp-adb-send-command - v (format "%s %s" - "ls" - (tramp-shell-quote-argument localname))) + v (format "ls %s" (tramp-shell-quote-argument localname))) (with-current-buffer (tramp-get-buffer v) (remove-if (lambda (l) (string-match "^[[:space:]]*$" l)) (split-string (buffer-string) "\n"))))) @@ -466,7 +463,7 @@ pass to the OPERATION." "Like `file-exists-p' for Tramp files." (with-parsed-tramp-file-name filename nil (with-file-property v localname "file-exists-p" - (tramp-adb-handle-file-attributes filename)))) + (file-attributes filename)))) ;; Helper functions -- 1.7.4.1
>From 994caee1a6dd31aa6eabf565583fc38a49535894 Mon Sep 17 00:00:00 2001 From: Michael Albinus <[email protected]> Date: Fri, 27 May 2011 22:58:00 +0200 Subject: [PATCH 4/6] Improve use of `tramp-adb-execute-adb-command'. --- tramp-adb.el | 32 +++++++++++++++----------------- 1 files changed, 15 insertions(+), 17 deletions(-) diff --git a/tramp-adb.el b/tramp-adb.el index 74ce588..1540f55 100644 --- a/tramp-adb.el +++ b/tramp-adb.el @@ -399,16 +399,10 @@ pass to the OPERATION." (tramp-error v 'file-error "Cannot make local copy of non-existing file `%s'" filename)) - (let* ((tmpfile (tramp-compat-make-temp-file filename)) - (fetch-command (format "%s pull %s %s" - (tramp-adb-program) - (shell-quote-argument localname) - (shell-quote-argument tmpfile)))) + (let ((tmpfile (tramp-compat-make-temp-file filename))) (with-progress-reporter - v 3 (format "Fetching %s to tmp file %s, using command: %s" - filename tmpfile fetch-command) - (unless (shell-command fetch-command) - ;;FIXME On Error we shall cleanup. + v 3 (format "Fetching %s to tmp file %s" filename tmpfile) + (when (tramp-adb-execute-adb-command v "pull" localname tmpfile) (delete-file tmpfile) (tramp-error v 'file-error "Cannot make local copy of file `%s'" filename))) @@ -447,10 +441,9 @@ pass to the OPERATION." (with-progress-reporter v 3 (format "Moving tmp file %s to %s" tmpfile filename) (unwind-protect - (let ((e (tramp-adb-execute-adb-command "push" (shell-quote-argument tmpfile) (shell-quote-argument localname)))) - (delete-file tmpfile) - (when e - (tramp-error v 'file-error "Cannot write: `%s'" e))))) + (when (tramp-adb-execute-adb-command v "push" tmpfile localname) + (tramp-error v 'file-error "Cannot write: `%s' filename")) + (delete-file tmpfile))) (unless (equal curbuf (current-buffer)) (tramp-error @@ -467,12 +460,17 @@ pass to the OPERATION." ;; Helper functions -(defun tramp-adb-execute-adb-command (&rest args) +(defun tramp-adb-execute-adb-command (vec &rest args) "Returns nil on success error-output on failure." + (when (tramp-file-name-host vec) + (setq args (append (list "-s" (tramp-file-name-host vec)) args))) (with-temp-buffer - (unless (zerop (apply 'call-process-shell-command - (tramp-adb-program) nil t nil args)) - (buffer-string)))) + (prog1 + (unless (zerop (apply 'call-process (tramp-adb-program) nil t nil args)) + (buffer-string)) + (tramp-message + vec 6 "%s %s\n%s" + (tramp-adb-program) (mapconcat 'identity args " ") (buffer-string))))) ;; Connection functions -- 1.7.4.1
>From 513c690babd5dbc18366ded1ad5f8238fa798a28 Mon Sep 17 00:00:00 2001 From: Michael Albinus <[email protected]> Date: Fri, 27 May 2011 22:59:52 +0200 Subject: [PATCH 5/6] Support host names. --- tramp-adb.el | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tramp-adb.el b/tramp-adb.el index 1540f55..fd7dba2 100644 --- a/tramp-adb.el +++ b/tramp-adb.el @@ -105,7 +105,13 @@ "Invoke the ADB handler for OPERATION. First arg specifies the OPERATION, second arg is a list of arguments to pass to the OPERATION." - (let ((fn (assoc operation tramp-adb-file-name-handler-alist))) + (let ((fn (assoc operation tramp-adb-file-name-handler-alist)) + ;; `tramp-default-host's default value is (system-name). Not + ;; useful for us. + (tramp-default-host + (unless (equal (eval (car (get 'tramp-default-host 'standard-value))) + tramp-default-host) + tramp-default-host))) (if fn (save-match-data (apply (cdr fn) args)) (tramp-run-real-handler operation args)))) @@ -546,13 +552,16 @@ connection if a previous connection has died for some reason." (with-progress-reporter vec 3 "Opening adb shell connection" (let* ((coding-system-for-read 'utf-8-dos) ;is this correct? (process-connection-type tramp-process-connection-type) + (args (if (tramp-file-name-host vec) + (list "-s" (tramp-file-name-host vec) "shell") + (list "shell"))) (p (let ((default-directory (tramp-compat-temporary-file-directory))) - (start-process (tramp-buffer-name vec) buf - (tramp-adb-program) "shell")))) + (apply 'start-process (tramp-buffer-name vec) buf + (tramp-adb-program) args)))) (tramp-message vec 6 "%s" (mapconcat 'identity (process-command p) " ")) - ;; wait for initial prompty + ;; Wait for initial prompt. (tramp-wait-for-regexp p nil "^[#\\$][[:space:]]+") (unless (eq 'run (process-status p)) (tramp-error vec 'file-error "Terminated!")) -- 1.7.4.1
>From a80d4c04255fe8b4972cc3dcf8f62a7b5b573ffb Mon Sep 17 00:00:00 2001 From: Michael Albinus <[email protected]> Date: Fri, 27 May 2011 23:38:51 +0200 Subject: [PATCH 6/6] Implement host name completion. --- tramp-adb.el | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/tramp-adb.el b/tramp-adb.el index fd7dba2..bdbd6d2 100644 --- a/tramp-adb.el +++ b/tramp-adb.el @@ -54,6 +54,10 @@ ;;;###tramp-autoload (add-to-list 'tramp-methods `(,tramp-adb-method)) +(eval-after-load 'tramp + '(tramp-set-completion-function + tramp-adb-method '((tramp-adb-parse-device-names "")))) + ;;;###tramp-autoload (add-to-list 'tramp-foreign-file-name-handler-alist (cons 'tramp-adb-file-name-p 'tramp-adb-file-name-handler)) @@ -121,6 +125,16 @@ pass to the OPERATION." "The Android Debug Bridge." (expand-file-name "platform-tools/adb" tramp-adb-sdk-dir)) +(defun tramp-adb-parse-device-names (ignore) + "Return a list of (nil host) tuples allowed to access." + (with-temp-buffer + (when (zerop (call-process (tramp-adb-program) nil t nil "devices")) + (let (result) + (goto-char (point-min)) + (while (search-forward-regexp "^\\(\\S-+\\)[[:space:]]+device$" nil t) + (add-to-list 'result (list nil (match-string 1)))) + result)))) + (defun tramp-adb-handle-expand-file-name (name &optional dir) "Like `expand-file-name' for Tramp files." ;; If DIR is not given, use DEFAULT-DIRECTORY or "/". -- 1.7.4.1
_______________________________________________ Tramp-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/tramp-devel
