Jürgen Hötzel <[email protected]> writes:

> Hi Michael,

Hi Juergen,

> Just the docstring/value of tramp-adb-ls-errors were shuffled:

The usual just-one-line-change-before-i-send-i-cannot-do-it-wrong ...

Enclosed the next patch set. Patch 0002 and 0003 were needed, because
I've tested today on a Windows XP machine, running Android SDK. There
seem to be still more oddities when being there, let's see next days.

Another question: why do you add this:

(add-to-list 'tramp-default-method-alist
             (list "\\`adb" nil tramp-adb-method))

It means: If somebody does not use an explicit method, but the host name
starts with "adb", the method "adb" shall be used.

I doubt, that there are devices with such a name, but who knows ... I'm
still not very familar with the Android world. But I feel we could
remove this setting.

Furthermore, some TODOs might be cleaned up in README.md for
tramp-adb-handle-insert-directory, I do not want to mess with this file.
And it seems to be possible to read on non-rooted devices at least, I've
tested it on my (non-rooted) Nexus S.

> Jürgen

Best regards, Michael.

>From 80d12036376bb18f12ae9e64bbb99cb8ba50c2db Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Tue, 24 May 2011 12:39:03 +0200
Subject: [PATCH 1/3] Use `tramp-adb-program' for executable name.

---
 tramp-adb.el |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/tramp-adb.el b/tramp-adb.el
index f1b04bc..42bbde7 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -113,6 +113,11 @@ pass to the OPERATION."
 	(save-match-data (apply (cdr fn) args))
       (tramp-run-real-handler operation args))))
 
+;; This cannot be a constant, because `tramp-adb-sdk-dir' is customizable.
+(defun tramp-adb-program ()
+  "The Android Debug Bridge."
+  (expand-file-name "platform-tools/adb" tramp-adb-sdk-dir))
+
 (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 "/".
@@ -315,11 +320,14 @@ pass to the OPERATION."
       (tramp-error
        v 'file-error
        "Cannot make local copy of non-existing file `%s'" filename))
-    (let* ((adb-program (expand-file-name "platform-tools/adb" (file-name-as-directory tramp-adb-sdk-dir)))
-	   (tmpfile (tramp-compat-make-temp-file filename))
-	   (fetch-command (concat adb-program " pull " (shell-quote-argument localname) " " (shell-quote-argument tmpfile))))
+    (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))))
       (with-progress-reporter
-	  v 3 (format "Fetching %s to tmp file %s, using command: %s" filename tmpfile fetch-command)
+	  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.
 	  (delete-file tmpfile)
@@ -382,10 +390,10 @@ pass to the OPERATION."
 
 (defun tramp-adb-execute-adb-command (&rest args)
   "Returns nil on success error-output on failure."
-  (let ((adb-program (expand-file-name "platform-tools/adb" (file-name-as-directory tramp-adb-sdk-dir))))
-    (with-temp-buffer
-      (unless (zerop (apply 'call-process-shell-command adb-program nil t nil args))
-	(buffer-string)))))
+  (with-temp-buffer
+    (unless (zerop (apply 'call-process-shell-command
+			  (tramp-adb-program) nil t nil args))
+      (buffer-string))))
 
 ;; Connection functions
 
@@ -433,8 +441,7 @@ Returns nil if there has been an error message from adb."
 Does not do anything if a connection is already open, but re-opens the
 connection if a previous connection has died for some reason."
   (let* ((buf (tramp-get-buffer vec))
-	 (p (get-buffer-process buf))
-	 (adb-program (expand-file-name "platform-tools/adb" (file-name-as-directory tramp-adb-sdk-dir))))
+	 (p (get-buffer-process buf)))
     (unless
 	(and p (processp p) (memq (process-status p) '(run open)))
       (save-match-data
@@ -444,7 +451,8 @@ connection if a previous connection has died for some reason."
 		 (process-connection-type tramp-process-connection-type)
 		 (p (let ((default-directory
 			    (tramp-compat-temporary-file-directory)))
-		      (start-process (tramp-buffer-name vec) (tramp-get-buffer vec) adb-program "shell"))))
+		      (start-process (tramp-buffer-name vec) buf
+				     (tramp-adb-program) "shell"))))
 	    (tramp-message
 	     vec 6 "%s" (mapconcat 'identity (process-command p) " "))
 	    ;; wait for initial prompty
-- 
1.7.4.1

>From 580b84d7210b279e94a5a3fb8e14e63f1ea66080 Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Wed, 25 May 2011 15:45:19 +0200
Subject: [PATCH 2/3] Remove trailing ^M on W32 machines.

---
 tramp-adb.el |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/tramp-adb.el b/tramp-adb.el
index 42bbde7..33fb985 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -408,8 +408,12 @@ Returns nil if there has been an error message from adb."
   (with-current-buffer (tramp-get-connection-buffer vec)
     (save-excursion
       (goto-char (point-min))
-      ;; we can't use stty to disable echo of command
-      (delete-matching-lines (regexp-quote command)))))
+      ;; We can't use stty to disable echo of command.
+      (delete-matching-lines (regexp-quote command))
+      ;; 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)))))
 
 (defun tramp-adb-wait-for-output (proc &optional timeout)
   "Wait for output from remote command."
-- 
1.7.4.1

>From 1fe29b65d9a04cbb8d4533258ec5d33f1bb9ee98 Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Wed, 25 May 2011 17:21:33 +0200
Subject: [PATCH 3/3] Add `tramp-adb-handle-file-truename'.

---
 tramp-adb.el |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/tramp-adb.el b/tramp-adb.el
index 33fb985..0a41041 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -71,6 +71,7 @@
     (file-attributes . tramp-adb-handle-file-attributes)
     (file-name-directory . tramp-handle-file-name-directory)
     (file-name-nondirectory . tramp-handle-file-name-nondirectory)
+    (file-truename . tramp-adb-handle-file-truename)
     (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
     (file-name-as-directory . tramp-handle-file-name-as-directory)
     (file-regular-p . tramp-handle-file-regular-p)
@@ -144,6 +145,88 @@ pass to the OPERATION."
       (and (file-exists-p filename)
 	   (car (file-attributes filename))))))
 
+;; This is derived from `tramp-sh-handle-file-truename'.  Maybe the
+;; code could be shared?
+(defun tramp-adb-handle-file-truename (filename &optional counter prev-dirs)
+  "Like `file-truename' for Tramp files."
+  (with-parsed-tramp-file-name (expand-file-name filename) nil
+    (with-file-property v localname "file-truename"
+      (let ((result nil))			; result steps in reverse order
+	(tramp-message v 4 "Finding true name for `%s'" filename)
+	(let* ((directory-sep-char ?/)
+	       (steps (tramp-compat-split-string localname "/"))
+	       (localnamedir (tramp-run-real-handler
+			      'file-name-as-directory (list localname)))
+	       (is-dir (string= localname localnamedir))
+	       (thisstep nil)
+	       (numchase 0)
+	       ;; Don't make the following value larger than
+	       ;; necessary.  People expect an error message in a
+	       ;; timely fashion when something is wrong; otherwise
+	       ;; they might think that Emacs is hung.  Of course,
+	       ;; correctness has to come first.
+	       (numchase-limit 20)
+	       symlink-target)
+	  (while (and steps (< numchase numchase-limit))
+	    (setq thisstep (pop steps))
+	    (tramp-message
+	     v 5 "Check %s"
+	     (mapconcat 'identity
+			(append '("") (reverse result) (list thisstep))
+			"/"))
+	    (setq symlink-target
+		  (nth 0 (file-attributes
+			  (tramp-make-tramp-file-name
+			   method user host
+			   (mapconcat 'identity
+				      (append '("")
+					      (reverse result)
+					      (list thisstep))
+				      "/")))))
+	    (cond ((string= "." thisstep)
+		   (tramp-message v 5 "Ignoring step `.'"))
+		  ((string= ".." thisstep)
+		   (tramp-message v 5 "Processing step `..'")
+		   (pop result))
+		  ((stringp symlink-target)
+		   ;; It's a symlink, follow it.
+		   (tramp-message v 5 "Follow symlink to %s" symlink-target)
+		   (setq numchase (1+ numchase))
+		   (when (file-name-absolute-p symlink-target)
+		     (setq result nil))
+		   ;; If the symlink was absolute, we'll get a string
+		   ;; like "/user@host:/some/target"; extract the
+		   ;; "/some/target" part from it.
+		   (when (tramp-tramp-file-p symlink-target)
+		     (unless (tramp-equal-remote filename symlink-target)
+		       (tramp-error
+			v 'file-error
+			"Symlink target `%s' on wrong host" symlink-target))
+		     (setq symlink-target localname))
+		   (setq steps
+			 (append (tramp-compat-split-string
+				  symlink-target "/")
+				 steps)))
+		  (t
+		   ;; It's a file.
+		   (setq result (cons thisstep result)))))
+	  (when (>= numchase numchase-limit)
+	    (tramp-error
+	     v 'file-error
+	     "Maximum number (%d) of symlinks exceeded" numchase-limit))
+	  (setq result (reverse result))
+	  ;; Combine list to form string.
+	  (setq result
+		(if result
+		    (mapconcat 'identity (cons "" result) "/")
+		  "/"))
+	  (when (and is-dir (or (string= "" result)
+				(not (string= (substring result -1) "/"))))
+	    (setq result (concat result "/"))))
+
+        (tramp-message v 4 "True name of `%s' is `%s'" filename result)
+        (tramp-make-tramp-file-name method user host result)))))
+
 (defun tramp-adb-handle-file-attributes (filename &optional id-format)
   "Like `file-attributes' for Tramp files."
   (unless id-format (setq id-format 'integer))
-- 
1.7.4.1

_______________________________________________
Tramp-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/tramp-devel

Reply via email to