From 7d11fc276327b0d2bd5045a03a1ca7f7f437e393 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Fri, 1 Mar 2013 22:12:26 +0100 Subject: [PATCH] * net/tramp-adb.el (tramp-adb-prompt): Extend regexp. (tramp-adb-handle-process-file): Remove superfluous setting. (tramp-adb-command-exit-status): Handle case that COMMAND is nil. (tramp-adb-barf-unless-okay): Use `tramp-adb-command-exit-status'. (tramp-adb-maybe-open-connection): Apply "su" if user is defined. --- lisp/ChangeLog | 8 +++++++ lisp/net/tramp-adb.el | 53 +++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 604435bfc61..8b6ffeed01d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2013-03-01 Michael Albinus + + * net/tramp-adb.el (tramp-adb-prompt): Extend regexp. + (tramp-adb-handle-process-file): Remove superfluous setting. + (tramp-adb-command-exit-status): Handle case that COMMAND is nil. + (tramp-adb-barf-unless-okay): Use `tramp-adb-command-exit-status'. + (tramp-adb-maybe-open-connection): Apply "su" if user is defined. + 2013-03-01 Stefan Monnier * textmodes/ispell.el: Fix nitpicks and byte-compiler warnings. diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 766dcdbbe6a..910356fbb6c 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -49,7 +49,7 @@ "*When this method name is used, forward all calls to Android Debug Bridge.") (defcustom tramp-adb-prompt - "^\\(?:[[:alnum:]]*@[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]" + "^\\(?:[[:digit:]]*|?\\)?\\(?:[[:alnum:]]*@[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]" "Regexp used as prompt in almquist shell." :type 'string :version "24.4" @@ -775,13 +775,11 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." ;; directory. (condition-case nil (progn - (setq ret 0 - ret - (tramp-adb-barf-unless-okay - v (format "(cd %s; %s)" - (tramp-shell-quote-argument localname) - command) - "")) + (setq ret 0) + (tramp-adb-barf-unless-okay + v (format "(cd %s; %s)" + (tramp-shell-quote-argument localname) command) + "") ;; We should show the output anyway. (when outbuf (with-current-buffer outbuf @@ -1011,34 +1009,31 @@ This happens for Android >= 4.0." (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-command-exit-status (vec command) "Run COMMAND and return its exit status. Sends `echo $?' along with the COMMAND for checking the exit status. If COMMAND is nil, just sends `echo $?'. Returns the exit status found." - (tramp-adb-send-command vec (format "%s; echo tramp_exit_status $?" command)) + (tramp-adb-send-command + vec (if command + (format "%s; echo tramp_exit_status $?" command) + "echo tramp_exit_status $?")) (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 "^ ") - (read (current-buffer)))) + (prog1 + (read (current-buffer)) + (let (buffer-read-only) + (delete-region (match-beginning 0) (point-max)))))) + +(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'." + (unless (zerop (tramp-adb-command-exit-status vec command)) + (apply 'tramp-error vec 'file-error fmt args))) (defun tramp-adb-wait-for-output (proc &optional timeout) "Wait for output from remote command." @@ -1077,6 +1072,7 @@ connection if a previous connection has died for some reason." (let* ((buf (tramp-get-connection-buffer vec)) (p (get-buffer-process buf)) (host (tramp-file-name-host vec)) + (user (tramp-file-name-user vec)) (devices (mapcar 'cadr (tramp-adb-parse-device-names nil)))) (unless (and p (processp p) (memq (process-status p) '(run open))) @@ -1132,6 +1128,13 @@ connection if a previous connection has died for some reason." old-getprop new-getprop) (tramp-adb-maybe-open-connection vec))) + ;; Change user if indicated. + (when user + (tramp-adb-send-command vec (format "su %s" user)) + (unless (zerop (tramp-adb-command-exit-status vec nil)) + (delete-process p) + (tramp-error vec 'file-error "Cannot switch to user %s" user))) + ;; Set "remote-path" connection property. This is needed ;; for eshell. (tramp-adb-send-command vec "echo \\\"$PATH\\\"") -- 2.39.2