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

> Hi Michael,

Hi Juergen,

> Excellent! Thank you very much for your contribution!

And so I have another series of patches ... I hope I don't bother you
too much.

Handling copy-file and rename-file as well as making insert-directory
more robust.

Now I feel ready to start with process handling.

> Jürgen

Best regards, Michael.

>From 3703d38e846e5a5d24c95d56d073a9d4c3b7ec5c Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Sat, 28 May 2011 13:48:01 +0200
Subject: [PATCH 1/9] Autoload `tramp-adb-parse-device-names'.

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

diff --git a/tramp-adb.el b/tramp-adb.el
index bdbd6d2..9120d1e 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -54,6 +54,7 @@
 ;;;###tramp-autoload
 (add-to-list 'tramp-methods `(,tramp-adb-method))
 
+;;;###tramp-autoload
 (eval-after-load 'tramp
   '(tramp-set-completion-function
     tramp-adb-method '((tramp-adb-parse-device-names ""))))
@@ -125,6 +126,7 @@ pass to the OPERATION."
   "The Android Debug Bridge."
   (expand-file-name "platform-tools/adb" tramp-adb-sdk-dir))
 
+;;;###tramp-autoload
 (defun tramp-adb-parse-device-names (ignore)
   "Return a list of (nil host) tuples allowed to access."
   (with-temp-buffer
-- 
1.7.4.1

>From f995a2d37a2da3e6bea4a1cecebd9b0aa353ed04 Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Sun, 29 May 2011 17:39:06 +0200
Subject: [PATCH 2/9] Add `tramp-adb-handle-set-file-modes'.

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

diff --git a/tramp-adb.el b/tramp-adb.el
index 9120d1e..e96d880 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -83,6 +83,7 @@
     (file-readable-p . tramp-handle-file-exists-p)
     (file-writable-p . tramp-adb-handle-file-writable-p)
     (file-local-copy . tramp-adb-handle-file-local-copy)
+    (file-modes . tramp-handle-file-modes)
     (expand-file-name . tramp-adb-handle-expand-file-name)
     (find-backup-file-name . tramp-handle-find-backup-file-name)
     (directory-files . tramp-adb-handle-directory-files)
@@ -96,6 +97,7 @@
     (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
     (vc-registered . ignore)	;no  vc control files on Android devices
     (write-region . tramp-adb-handle-write-region)
+    (set-file-modes . tramp-adb-handle-set-file-modes)
     (rename-file . tramp-sh-handle-rename-file))
   "Alist of handler functions for Tramp ADB method.")
 
@@ -472,6 +474,14 @@ pass to the OPERATION."
 	 v 'file-error
 	 "Buffer has changed from `%s' to `%s'" curbuf (current-buffer))))))
 
+(defun tramp-adb-handle-set-file-modes (filename mode)
+  "Like `set-file-modes' for Tramp files."
+  (with-parsed-tramp-file-name filename nil
+    (tramp-flush-file-property v localname)
+    (tramp-adb-barf-unless-okay
+     v (format "chmod %s %s" (tramp-compat-decimal-to-octal mode) localname)
+     "Error while changing file's mode %s" filename)))
+
 ;;; Android doesn't provide test command
 
 (defun tramp-adb-handle-file-exists-p (filename)
-- 
1.7.4.1

>From b0750e490f36fb041c5daaf2fc64d22e235a522e Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Sun, 29 May 2011 17:42:42 +0200
Subject: [PATCH 3/9] Add `tramp-adb-handle-copy-file'.

---
 tramp-adb.el |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/tramp-adb.el b/tramp-adb.el
index e96d880..b1e4f99 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -98,6 +98,8 @@
     (vc-registered . ignore)	;no  vc control files on Android devices
     (write-region . tramp-adb-handle-write-region)
     (set-file-modes . tramp-adb-handle-set-file-modes)
+    (set-file-times . ignore)
+    (copy-file . tramp-adb-handle-copy-file)
     (rename-file . tramp-sh-handle-rename-file))
   "Alist of handler functions for Tramp ADB method.")
 
@@ -429,7 +431,8 @@ pass to the OPERATION."
 	(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)))
+	   v 'file-error "Cannot make local copy of file `%s'" filename))
+	(set-file-modes tmpfile (file-modes filename)))
       tmpfile)))
 
 (defun tramp-adb-handle-file-writable-p (filename)
@@ -482,6 +485,48 @@ pass to the OPERATION."
      v (format "chmod %s %s" (tramp-compat-decimal-to-octal mode) localname)
      "Error while changing file's mode %s" filename)))
 
+(defun tramp-adb-handle-copy-file
+  (filename newname &optional ok-if-already-exists keep-date
+	    preserve-uid-gid preserve-selinux-context)
+  "Like `copy-file' for Tramp files.
+PRESERVE-UID-GID and PRESERVE-SELINUX-CONTEXT are completely ignored."
+  (setq filename (expand-file-name filename)
+	newname (expand-file-name newname))
+  (with-progress-reporter
+      (tramp-dissect-file-name (if (file-remote-p filename) filename newname))
+      0 (format "Copying %s to %s" filename newname)
+
+    (let ((tmpfile (file-local-copy filename)))
+
+      (if tmpfile
+	  ;; Remote filename.
+	  (condition-case err
+	      (rename-file tmpfile newname ok-if-already-exists)
+	    ((error quit)
+	     (delete-file tmpfile)
+	     (signal (car err) (cdr err))))
+
+	;; Remote newname.
+	(when (file-directory-p newname)
+	  (setq newname
+		(expand-file-name (file-name-nondirectory filename) newname)))
+
+	(with-parsed-tramp-file-name newname nil
+	  (when (and (not ok-if-already-exists)
+		     (file-exists-p newname))
+	    (tramp-error v 'file-already-exists newname))
+
+	  ;; We must also flush the cache of the directory, because
+	  ;; `file-attributes' reads the values from there.
+	  (tramp-flush-file-property v (file-name-directory localname))
+	  (tramp-flush-file-property v localname)
+	  (when (tramp-adb-execute-adb-command v "push" filename localname)
+	    (tramp-error
+	     v 'file-error "Cannot copy `%s' `%s'" filename newname))))))
+
+  ;; KEEP-DATE handling.
+  (when keep-date (set-file-times newname (nth 5 (file-attributes filename)))))
+
 ;;; Android doesn't provide test command
 
 (defun tramp-adb-handle-file-exists-p (filename)
-- 
1.7.4.1

>From 46ff502bb6542f286f682eebdb359320c0b7de53 Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Sun, 29 May 2011 17:44:03 +0200
Subject: [PATCH 4/9] Add `tramp-adb-handle-rename-file'.

---
 tramp-adb.el |   34 +++++++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/tramp-adb.el b/tramp-adb.el
index b1e4f99..f788662 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -33,7 +33,7 @@
 
 ;;; Code:
 
-(require 'tramp-sh)
+(require 'tramp)
 
 (defcustom tramp-adb-sdk-dir "~/Android/sdk"
   "Set to the directory containing the Android SDK."
@@ -100,7 +100,7 @@
     (set-file-modes . tramp-adb-handle-set-file-modes)
     (set-file-times . ignore)
     (copy-file . tramp-adb-handle-copy-file)
-    (rename-file . tramp-sh-handle-rename-file))
+    (rename-file . tramp-adb-handle-rename-file))
   "Alist of handler functions for Tramp ADB method.")
 
 ;;;###tramp-autoload
@@ -527,7 +527,35 @@ PRESERVE-UID-GID and PRESERVE-SELINUX-CONTEXT are completely ignored."
   ;; KEEP-DATE handling.
   (when keep-date (set-file-times newname (nth 5 (file-attributes filename)))))
 
-;;; Android doesn't provide test command
+(defun tramp-adb-handle-rename-file
+  (filename newname &optional ok-if-already-exists)
+  "Like `rename-file' for Tramp files."
+  (setq filename (expand-file-name filename)
+	newname (expand-file-name newname))
+
+  (with-parsed-tramp-file-name
+      (if (file-remote-p filename) filename newname) nil
+    (with-progress-reporter v 0 (format "Renaming %s to %s" newname filename)
+
+      (if (tramp-equal-remote filename newname)
+	  (progn
+	    (when (and (not ok-if-already-exists)
+		       (file-exists-p newname))
+	      (tramp-error v 'file-already-exists newname))
+	    ;; We must also flush the cache of the directory, because
+	    ;; `file-attributes' reads the values from there.
+	    (tramp-flush-file-property v (file-name-directory localname))
+	    (tramp-flush-file-property v localname)
+	    ;; Short track.
+	    (tramp-adb-barf-unless-okay
+	     v (format "mv %s %s" (file-remote-p filename 'localname) localname)
+	     "Error renaming %s to %s" filename newname))
+
+	;; Rename by copy.
+	(copy-file filename newname ok-if-already-exists t t)
+	(delete-file filename)))))
+
+;; Android doesn't provide test command
 
 (defun tramp-adb-handle-file-exists-p (filename)
   "Like `file-exists-p' for Tramp files."
-- 
1.7.4.1

>From 09d0f94e05b73535844bb2d876eea720f086f81d Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Sun, 29 May 2011 22:22:21 +0200
Subject: [PATCH 5/9] Improve directory listings, support partial listings. Simplify error handling.

---
 tramp-adb.el |  113 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 60 insertions(+), 53 deletions(-)

diff --git a/tramp-adb.el b/tramp-adb.el
index f788662..2630179 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -44,11 +44,6 @@
 (defconst tramp-adb-method "adb"
   "*When this method name is used, forward all calls to Android Debug Bridge.")
 
-(defconst tramp-adb-ls-errors
-  (regexp-opt '("No such file or directory"
-		"opendir failed, Permission denied"))
-  "Error strings returned by the \"ls\" command.")
-
 (defconst tramp-adb-ls-date-regexp "[[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]][0-9][0-9]:[0-9][0-9][[:space:]]")
 
 ;;;###tramp-autoload
@@ -260,35 +255,36 @@ pass to the OPERATION."
 (defun tramp-adb-handle-file-attributes (filename &optional id-format)
   "Like `file-attributes' for Tramp files."
   (unless id-format (setq id-format 'integer))
-  (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)))
-      (with-current-buffer (tramp-get-buffer v)
-	(unless (string-match tramp-adb-ls-errors (buffer-string))
-	  (tramp-adb-sh-fix-ls-output)
-	  (let* ((columns (split-string (buffer-string)))
-		 (mod-string (nth 0 columns))
-		 (is-dir (eq ?d (aref mod-string 0)))
-		 (is-symlink (eq ?l (aref mod-string 0)))
-		 (symlink-target (and is-symlink (cadr (split-string (buffer-string) "\\( -> \\|\n\\)"))))
-		 (uid (nth 1 columns))
-		 (gid (nth 2 columns))
-		 (date (format "%s %s" (nth 4 columns) (nth 5 columns)))
-		 (size (string-to-int (nth 3 columns))))
-	    (list
-	     (or is-dir symlink-target)
-	     1 					;link-count
-	     ;; no way to handle numeric ids in Androids ash
-	     (if (eq id-format 'integer) 0 uid)
-	     (if (eq id-format 'integer) 0 gid)
-	     '(0 0) ; atime
-	     (date-to-time date) ; mtime
-	     '(0 0) ; ctime
-	     size
-	     mod-string
-	     ;; fake
-	     t 1 1)))))))
+  (ignore-errors
+    (with-parsed-tramp-file-name filename nil
+      (with-file-property v localname (format "file-attributes-%s" id-format)
+	(tramp-adb-barf-unless-okay
+	 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)
+	    (let* ((columns (split-string (buffer-string)))
+		   (mod-string (nth 0 columns))
+		   (is-dir (eq ?d (aref mod-string 0)))
+		   (is-symlink (eq ?l (aref mod-string 0)))
+		   (symlink-target (and is-symlink (cadr (split-string (buffer-string) "\\( -> \\|\n\\)"))))
+		   (uid (nth 1 columns))
+		   (gid (nth 2 columns))
+		   (date (format "%s %s" (nth 4 columns) (nth 5 columns)))
+		   (size (string-to-int (nth 3 columns))))
+	      (list
+	       (or is-dir symlink-target)
+	       1 					;link-count
+	       ;; no way to handle numeric ids in Androids ash
+	       (if (eq id-format 'integer) 0 uid)
+	       (if (eq id-format 'integer) 0 gid)
+	       '(0 0) ; atime
+	       (date-to-time date) ; mtime
+	       '(0 0) ; ctime
+	       size
+	       mod-string
+	       ;; fake
+	       t 1 1))))))))
 
 (defun tramp-adb--gnu-switches-to-ash
   (switches)
@@ -307,23 +303,25 @@ pass to the OPERATION."
   (when (stringp switches)
     (setq switches (tramp-adb--gnu-switches-to-ash (split-string switches))))
   (with-parsed-tramp-file-name (expand-file-name filename) nil
-    (let ((cmd (format "ls %s "
-		       (mapconcat 'identity (remove "-t" switches) " ")))
-	  (name
-	   (tramp-shell-quote-argument (file-name-as-directory localname))))
-      ;; We insert also filename/. and filename/.., because "ls" doesn't.
-      (dolist (string
-	       (list (concat "-d " name ".")
-		     (concat "-d " name "..")
-		     name))
-	(tramp-adb-send-command v (concat cmd string))
-	(let ((result
-	       (with-current-buffer (tramp-get-buffer v) (buffer-string))))
-	  (when (string-match tramp-adb-ls-errors result)
-	    (tramp-error
-	     v 'file-error "%s: %s" (match-string 0 result) localname))
-	  (insert result)))
-      (tramp-adb-sh-fix-ls-output (member "-t" switches)))))
+    (let ((name (tramp-shell-quote-argument (directory-file-name localname)))
+	  (switch-d (member "-d" switches))
+	  (switch-t (member "-t" switches))
+	  (switches (mapconcat 'identity (remove "-t" switches) " ")))
+      (tramp-adb-barf-unless-okay
+       v (format "ls %s %s" switches name)
+       "Cannot insert directory listing: %s" filename)
+      (insert (with-current-buffer (tramp-get-buffer v) (buffer-string)))
+      (unless  switch-d
+	;; We insert also filename/. and filename/.., because "ls" doesn't.
+	(ignore-errors
+	  (tramp-adb-barf-unless-okay
+	   v (format "ls -d %s %s %s"
+		     switches
+		     (concat (file-name-as-directory name) ".")
+		     (concat (file-name-as-directory name) ".."))
+	   "Cannot insert directory listing: %s" filename)
+	  (insert (with-current-buffer (tramp-get-buffer v) (buffer-string)))))
+      (tramp-adb-sh-fix-ls-output switch-t))))
 
 (defun tramp-adb-sh-fix-ls-output (&optional sort-by-time)
   "Androids ls command doesn't insert size column for directories: Emacs dired can't find files. Insert dummy 0 in empty size columns."
@@ -331,7 +329,11 @@ pass to the OPERATION."
     ;; Insert missing size.
     (goto-char (point-min))
     (while (search-forward-regexp "[[:space:]]\\([[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]]\\)" nil t)
-      (replace-match "0\\1" "\\1" nil))
+      (replace-match "0\\1" "\\1" nil)
+      ;; Insert missing "/".
+      (when (looking-at "[0-9][0-9]:[0-9][0-9][[:space:]]+$")
+	(end-of-line)
+	(insert "/")))
     ;; Sort entries.
     (let* ((lines (split-string (buffer-string) "\n" t))
 	   (sorted-lines
@@ -341,7 +343,12 @@ pass to the OPERATION."
 		 'tramp-adb-ls-output-time-less-p
 	       'tramp-adb-ls-output-name-less-p))))
       (delete-region (point-min) (point-max))
-      (insert "  " (mapconcat 'identity sorted-lines "\n  ")))))
+      (insert "  " (mapconcat 'identity sorted-lines "\n  ")))
+    ;; Add final newline.
+    (goto-char (point-max))
+    (unless (= (point) (line-beginning-position))
+      (insert "\n"))))
+
 
 (defun tramp-adb-ls-output-time-less-p (a b)
   "Sort \"ls\" output by time, descending."
-- 
1.7.4.1

>From db2331962c84e8e73f1f7a4aae32a3f16e901ee6 Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Sun, 29 May 2011 22:24:57 +0200
Subject: [PATCH 6/9] Allow directories for `tramp-adb-handle-copy-file' and `tramp-adb-handle-rename-file'.

---
 tramp-adb.el |   74 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/tramp-adb.el b/tramp-adb.el
index 2630179..b98899f 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -296,7 +296,6 @@ pass to the OPERATION."
 				       (remove-if (lambda (s)
 						    (string-match  "\\(^--\\|^[^-]\\)" s)) switches)))))
 
-
 (defun tramp-adb-handle-insert-directory
   (filename switches &optional wildcard full-directory-p)
   "Like `insert-directory' for Tramp files."
@@ -499,40 +498,44 @@ pass to the OPERATION."
 PRESERVE-UID-GID and PRESERVE-SELINUX-CONTEXT are completely ignored."
   (setq filename (expand-file-name filename)
 	newname (expand-file-name newname))
-  (with-progress-reporter
-      (tramp-dissect-file-name (if (file-remote-p filename) filename newname))
-      0 (format "Copying %s to %s" filename newname)
-
-    (let ((tmpfile (file-local-copy filename)))
-
-      (if tmpfile
-	  ;; Remote filename.
-	  (condition-case err
-	      (rename-file tmpfile newname ok-if-already-exists)
-	    ((error quit)
-	     (delete-file tmpfile)
-	     (signal (car err) (cdr err))))
-
-	;; Remote newname.
-	(when (file-directory-p newname)
-	  (setq newname
-		(expand-file-name (file-name-nondirectory filename) newname)))
-
-	(with-parsed-tramp-file-name newname nil
-	  (when (and (not ok-if-already-exists)
-		     (file-exists-p newname))
-	    (tramp-error v 'file-already-exists newname))
-
-	  ;; We must also flush the cache of the directory, because
-	  ;; `file-attributes' reads the values from there.
-	  (tramp-flush-file-property v (file-name-directory localname))
-	  (tramp-flush-file-property v localname)
-	  (when (tramp-adb-execute-adb-command v "push" filename localname)
-	    (tramp-error
-	     v 'file-error "Cannot copy `%s' `%s'" filename newname))))))
 
-  ;; KEEP-DATE handling.
-  (when keep-date (set-file-times newname (nth 5 (file-attributes filename)))))
+  (if (file-directory-p filename)
+      (copy-directory filename keep-date)
+    (with-progress-reporter
+	(tramp-dissect-file-name (if (file-remote-p filename) filename newname))
+	0 (format "Copying %s to %s" filename newname)
+
+      (let ((tmpfile (file-local-copy filename)))
+
+	(if tmpfile
+	    ;; Remote filename.
+	    (condition-case err
+		(rename-file tmpfile newname ok-if-already-exists)
+	      ((error quit)
+	       (delete-file tmpfile)
+	       (signal (car err) (cdr err))))
+
+	  ;; Remote newname.
+	  (when (file-directory-p newname)
+	    (setq newname
+		  (expand-file-name (file-name-nondirectory filename) newname)))
+
+	  (with-parsed-tramp-file-name newname nil
+	    (when (and (not ok-if-already-exists)
+		       (file-exists-p newname))
+	      (tramp-error v 'file-already-exists newname))
+
+	    ;; We must also flush the cache of the directory, because
+	    ;; `file-attributes' reads the values from there.
+	    (tramp-flush-file-property v (file-name-directory localname))
+	    (tramp-flush-file-property v localname)
+	    (when (tramp-adb-execute-adb-command v "push" filename localname)
+	      (tramp-error
+	       v 'file-error "Cannot copy `%s' `%s'" filename newname))))))
+
+    ;; KEEP-DATE handling.
+    (when keep-date
+      (set-file-times newname (nth 5 (file-attributes filename))))))
 
 (defun tramp-adb-handle-rename-file
   (filename newname &optional ok-if-already-exists)
@@ -544,7 +547,8 @@ PRESERVE-UID-GID and PRESERVE-SELINUX-CONTEXT are completely ignored."
       (if (file-remote-p filename) filename newname) nil
     (with-progress-reporter v 0 (format "Renaming %s to %s" newname filename)
 
-      (if (tramp-equal-remote filename newname)
+      (if (and (tramp-equal-remote filename newname)
+	       (not (file-directory-p filename)))
 	  (progn
 	    (when (and (not ok-if-already-exists)
 		       (file-exists-p newname))
-- 
1.7.4.1

>From 8c2bba02f053d2467a4182c047e7cfe68de80455 Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Mon, 30 May 2011 17:50:29 +0200
Subject: [PATCH 7/9] Get rid of special shell prompt setting, we don't need it.

---
 tramp-adb.el |   64 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/tramp-adb.el b/tramp-adb.el
index b98899f..69c3401 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -44,6 +44,9 @@
 (defconst tramp-adb-method "adb"
   "*When this method name is used, forward all calls to Android Debug Bridge.")
 
+(defconst tramp-adb-prompt "^[#\\$][[:space:]]+"
+  "Regexp used as prompt in ADB shell.")
+
 (defconst tramp-adb-ls-date-regexp "[[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]][0-9][0-9]:[0-9][0-9][[:space:]]")
 
 ;;;###tramp-autoload
@@ -261,30 +264,29 @@ pass to the OPERATION."
 	(tramp-adb-barf-unless-okay
 	 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)
-	    (let* ((columns (split-string (buffer-string)))
-		   (mod-string (nth 0 columns))
-		   (is-dir (eq ?d (aref mod-string 0)))
-		   (is-symlink (eq ?l (aref mod-string 0)))
-		   (symlink-target (and is-symlink (cadr (split-string (buffer-string) "\\( -> \\|\n\\)"))))
-		   (uid (nth 1 columns))
-		   (gid (nth 2 columns))
-		   (date (format "%s %s" (nth 4 columns) (nth 5 columns)))
-		   (size (string-to-int (nth 3 columns))))
-	      (list
-	       (or is-dir symlink-target)
-	       1 					;link-count
-	       ;; no way to handle numeric ids in Androids ash
-	       (if (eq id-format 'integer) 0 uid)
-	       (if (eq id-format 'integer) 0 gid)
-	       '(0 0) ; atime
-	       (date-to-time date) ; mtime
-	       '(0 0) ; ctime
-	       size
-	       mod-string
-	       ;; fake
-	       t 1 1))))))))
+	  (tramp-adb-sh-fix-ls-output)
+	  (let* ((columns (split-string (buffer-string)))
+		 (mod-string (nth 0 columns))
+		 (is-dir (eq ?d (aref mod-string 0)))
+		 (is-symlink (eq ?l (aref mod-string 0)))
+		 (symlink-target (and is-symlink (cadr (split-string (buffer-string) "\\( -> \\|\n\\)"))))
+		 (uid (nth 1 columns))
+		 (gid (nth 2 columns))
+		 (date (format "%s %s" (nth 4 columns) (nth 5 columns)))
+		 (size (string-to-int (nth 3 columns))))
+	    (list
+	     (or is-dir symlink-target)
+	     1 					;link-count
+	     ;; no way to handle numeric ids in Androids ash
+	     (if (eq id-format 'integer) 0 uid)
+	     (if (eq id-format 'integer) 0 gid)
+	     '(0 0) ; atime
+	     (date-to-time date) ; mtime
+	     '(0 0) ; ctime
+	     size
+	     mod-string
+	     ;; fake
+	     t 1 1)))))))
 
 (defun tramp-adb--gnu-switches-to-ash
   (switches)
@@ -630,24 +632,24 @@ FMT and ARGS are passed to `error'."
     (delete-process proc)
     (tramp-error proc 'file-error "Process `%s' not available, try again" proc))
   (with-current-buffer (process-buffer proc)
-    (if (tramp-wait-for-regexp proc timeout (regexp-quote tramp-end-of-output))
+    (if (tramp-wait-for-regexp proc timeout tramp-adb-prompt)
 	(let (buffer-read-only)
 	  (goto-char (point-min))
-	  (when (search-forward tramp-end-of-output (point-at-eol) t)
+	  (when (search-forward tramp-adb-prompt (point-at-eol) t)
 	    (forward-line 1)
 	    (delete-region (point-min) (point)))
 	  ;; Delete the prompt.
 	  (goto-char (point-max))
-	  (search-backward tramp-end-of-output nil t)
+	  (search-backward tramp-adb-prompt nil t)
 	  (delete-region (point) (point-max)))
       (if timeout
 	  (tramp-error
 	   proc 'file-error
 	   "[[Remote adb prompt `%s' not found in %d secs]]"
-	   tramp-end-of-output timeout)
+	   tramp-adb-prompt timeout)
 	(tramp-error
 	 proc 'file-error
-	 "[[Remote prompt `%s' not found]]" tramp-end-of-output)))))
+	 "[[Remote prompt `%s' not found]]" tramp-adb-prompt)))))
 
 (defun tramp-adb-maybe-open-connection (vec)
   "Maybe open a connection VEC.
@@ -672,11 +674,9 @@ connection if a previous connection has died for some reason."
 	    (tramp-message
 	     vec 6 "%s" (mapconcat 'identity (process-command p) " "))
 	    ;; Wait for initial prompt.
-	    (tramp-wait-for-regexp p nil "^[#\\$][[:space:]]+")
+	    (tramp-adb-wait-for-output p)
 	    (unless (eq 'run (process-status p))
 	      (tramp-error  vec 'file-error "Terminated!"))
-	    (tramp-send-command
-	     vec (format "PS1=%s" (shell-quote-argument tramp-end-of-output)) t)
 	    (set-process-query-on-exit-flag p nil)))))))
 
 (provide 'tramp-adb)
-- 
1.7.4.1

>From ead32b682d960f8364dfa9f1e05bcb4fd5c50a85 Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Tue, 31 May 2011 12:38:40 +0200
Subject: [PATCH 8/9] Fix arguments in `copy-directory' call.

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

diff --git a/tramp-adb.el b/tramp-adb.el
index 69c3401..03f6b31 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -502,7 +502,7 @@ PRESERVE-UID-GID and PRESERVE-SELINUX-CONTEXT are completely ignored."
 	newname (expand-file-name newname))
 
   (if (file-directory-p filename)
-      (copy-directory filename keep-date)
+      (copy-directory filename newname keep-date)
     (with-progress-reporter
 	(tramp-dissect-file-name (if (file-remote-p filename) filename newname))
 	0 (format "Copying %s to %s" filename newname)
-- 
1.7.4.1

>From d80b45f0a9ec912a55f952cda5cc5ee53f72ac50 Mon Sep 17 00:00:00 2001
From: Michael Albinus <[email protected]>
Date: Tue, 31 May 2011 14:13:12 +0200
Subject: [PATCH 9/9] Make `tramp-adb-handle-insert-directory' capable to insert partial directory listings.

---
 tramp-adb.el |   59 ++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/tramp-adb.el b/tramp-adb.el
index 03f6b31..991567a 100644
--- a/tramp-adb.el
+++ b/tramp-adb.el
@@ -290,13 +290,18 @@ pass to the OPERATION."
 
 (defun tramp-adb--gnu-switches-to-ash
   (switches)
-  "Almquist shell can't handle multiple arguments. Convert (\"-al\") to (\"-a\" \"-l\")"
-  (split-string (apply 'concat (mapcar (lambda (s)
-					 (replace-regexp-in-string "\\(.\\)"  " -\\1"
-								   (replace-regexp-in-string "^-" "" s)))
-				       ;; FIXME: Warning about removed switches (long and non-dash)
-				       (remove-if (lambda (s)
-						    (string-match  "\\(^--\\|^[^-]\\)" s)) switches)))))
+  "Almquist shell can't handle multiple arguments.
+Convert (\"-al\") to (\"-a\" \"-l\").  Remove arguments like \"--dired\"."
+  (split-string
+   (apply 'concat
+	  (mapcar (lambda (s)
+		    (replace-regexp-in-string
+		     "\\(.\\)"  " -\\1"
+		     (replace-regexp-in-string "^-" "" s)))
+		  ;; FIXME: Warning about removed switches (long and non-dash).
+		  (remove-if
+		   (lambda (s) (string-match "\\(^--\\|^[^-]\\)" s))
+		   switches)))))
 
 (defun tramp-adb-handle-insert-directory
   (filename switches &optional wildcard full-directory-p)
@@ -304,25 +309,27 @@ pass to the OPERATION."
   (when (stringp switches)
     (setq switches (tramp-adb--gnu-switches-to-ash (split-string switches))))
   (with-parsed-tramp-file-name (expand-file-name filename) nil
-    (let ((name (tramp-shell-quote-argument (directory-file-name localname)))
-	  (switch-d (member "-d" switches))
-	  (switch-t (member "-t" switches))
-	  (switches (mapconcat 'identity (remove "-t" switches) " ")))
-      (tramp-adb-barf-unless-okay
-       v (format "ls %s %s" switches name)
-       "Cannot insert directory listing: %s" filename)
-      (insert (with-current-buffer (tramp-get-buffer v) (buffer-string)))
-      (unless  switch-d
-	;; We insert also filename/. and filename/.., because "ls" doesn't.
-	(ignore-errors
-	  (tramp-adb-barf-unless-okay
-	   v (format "ls -d %s %s %s"
-		     switches
-		     (concat (file-name-as-directory name) ".")
-		     (concat (file-name-as-directory name) ".."))
-	   "Cannot insert directory listing: %s" filename)
-	  (insert (with-current-buffer (tramp-get-buffer v) (buffer-string)))))
-      (tramp-adb-sh-fix-ls-output switch-t))))
+    (with-current-buffer (tramp-get-buffer v)
+      (let ((name (tramp-shell-quote-argument (directory-file-name localname)))
+	    (switch-d (member "-d" switches))
+	    (switch-t (member "-t" switches))
+	    (switches (mapconcat 'identity (remove "-t" switches) " ")))
+	(tramp-adb-barf-unless-okay
+	 v (format "ls %s %s" switches name)
+	 "Cannot insert directory listing: %s" filename)
+	(unless switch-d
+	  ;; We insert also filename/. and filename/.., because "ls" doesn't.
+	  (narrow-to-region (point) (point))
+	  (ignore-errors
+	    (tramp-adb-barf-unless-okay
+	     v (format "ls -d %s %s %s"
+		       switches
+		       (concat (file-name-as-directory name) ".")
+		       (concat (file-name-as-directory name) ".."))
+	     "Cannot insert directory listing: %s" filename))
+	  (widen))
+	(tramp-adb-sh-fix-ls-output switch-t)))
+    (insert-buffer-substring (tramp-get-buffer v))))
 
 (defun tramp-adb-sh-fix-ls-output (&optional sort-by-time)
   "Androids ls command doesn't insert size column for directories: Emacs dired can't find files. Insert dummy 0 in empty size columns."
-- 
1.7.4.1

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

Reply via email to