]> git.eshelyaron.com Git - emacs.git/commitdiff
Adapt Tramp for Android 12
authorMichael Albinus <michael.albinus@gmx.de>
Sat, 6 Aug 2022 16:09:35 +0000 (18:09 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Sat, 6 Aug 2022 16:09:35 +0000 (18:09 +0200)
* lisp/net/tramp-adb.el (tramp-methods): Use "%d".
(tramp-adb-handle-directory-files-and-attributes): Fix "." and
".." in listing.
(tramp-adb-sh-fix-ls-output): Fix file names with spaces.
(tramp-adb-maybe-open-connection): Compute args from `tramp-login-args'.

* lisp/net/tramp.el (tramp-methods): Adapt docstring.
(tramp-handle-make-process): Check for adb device if indicated.

* test/lisp/net/tramp-tests.el (tramp-test17-insert-directory)
(tramp-test22-file-times): Adapt tests.

lisp/net/tramp-adb.el
lisp/net/tramp.el
test/lisp/net/tramp-tests.el

index 918de68ea9bd8a2260e55dea5710125b2db90e97..ed51628c4a7ba328874709268529fc8243b26b52 100644 (file)
@@ -95,7 +95,7 @@ It is used for TCP/IP devices."
  (add-to-list 'tramp-methods
              `(,tramp-adb-method
                 (tramp-login-program ,tramp-adb-program)
-                (tramp-login-args    (("shell")))
+                (tramp-login-args    (("-s" "%d") ("shell")))
                 (tramp-direct-async  t)
                (tramp-tmpdir        "/data/local/tmp")
                 (tramp-default-port  5555)))
@@ -325,6 +325,11 @@ arguments to pass to the OPERATION."
                      (tramp-compat-file-name-concat localname "."))
                     (tramp-shell-quote-argument
                      (tramp-compat-file-name-concat localname ".."))))
+         (replace-regexp-in-region
+          (regexp-quote
+           (tramp-compat-file-name-unquote
+            (file-name-as-directory localname)))
+          "" (point-min))
          (widen)))
       (tramp-adb-sh-fix-ls-output)
       (tramp-do-parse-file-attributes-with-ls v))))
@@ -357,6 +362,10 @@ arguments to pass to the OPERATION."
 Android's \"ls\" command doesn't insert size column for directories:
 Emacs dired can't find files."
   (save-excursion
+    ;; Fix file names with spaces.
+    ;; FIXME: It would be better if we could call "ls" with proper
+    ;; argument or environment variable.
+    (replace-string-in-region "\\ " " " (point-min))
     ;; Insert missing size.
     (goto-char (point-min))
     (while
@@ -1240,9 +1249,8 @@ connection if a previous connection has died for some reason."
        (with-tramp-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 (> (length host) 0)
-                          (list "-s" device "shell")
-                        (list "shell")))
+                (args (tramp-expand-args
+                       vec 'tramp-login-args ?d (or device "")))
                 (p (let ((default-directory
                            tramp-compat-temporary-file-directory))
                      (apply #'start-process (tramp-get-connection-name vec) buf
index ae31287ecedcda6ca9c594e187d05b374a14990d..4cc4ee0722ecf3c8e7168c81abd5cf817aa480cb 100644 (file)
@@ -263,6 +263,7 @@ pair of the form (KEY VALUE).  The following KEYs are defined:
       argument if it is supported.
     - \"%z\" is replaced by the `tramp-scp-direct-remote-copying'
       argument if it is supported.
+    - \"%d\" is replaced by the device detected by `tramp-adb-get-device'.
 
     The existence of `tramp-login-args', combined with the
     absence of `tramp-copy-args', is an indication that the
@@ -4755,6 +4756,7 @@ substitution.  SPEC-LIST is a list of char/value pairs used for
          ;; is different between tramp-sh.el, and tramp-adb.el or
          ;; tramp-sshfs.el.
          (let* ((sh-file-name-handler-p (tramp-sh-file-name-handler-p v))
+                (adb-file-name-handler-p (tramp-adb-file-name-p v))
                 (login-program
                  (tramp-get-method-parameter v 'tramp-login-program))
                 ;; We don't create the temporary file.  In fact, it
@@ -4774,6 +4776,10 @@ substitution.  SPEC-LIST is a list of char/value pairs used for
                  (when sh-file-name-handler-p
                    (tramp-compat-funcall
                     'tramp-ssh-controlmaster-options v)))
+                (device
+                 (when adb-file-name-handler-p
+                   (tramp-compat-funcall
+                    'tramp-adb-get-device v)))
                 login-args p)
 
            ;; Replace `login-args' place holders.  Split
@@ -4790,7 +4796,7 @@ substitution.  SPEC-LIST is a list of char/value pairs used for
                 v 'tramp-login-args
                 ?h (or host "") ?u (or user "") ?p (or port "")
                 ?c (format-spec (or options "") (format-spec-make ?t tmpfile))
-                ?l ""))))
+                ?d (or device "") ?l ""))))
             p (make-process
                :name name :buffer buffer
                :command (append `(,login-program) login-args command)
index e2d4ed781bbc493778e69357b1a4f03c7fc2c1e8..e2cafc240b959f49d523ebb7113f318c6b03eeba 100644 (file)
@@ -3232,20 +3232,21 @@ This tests also `file-directory-p' and `file-accessible-directory-p'."
              (goto-char (point-min))
              (should
               (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1)))))
-           (with-temp-buffer
-             (insert-directory
-              (file-name-as-directory tmp-name1) "-al" nil 'full-directory-p)
-             (goto-char (point-min))
-             (should
-              (looking-at-p
-               (concat
-                ;; There might be a summary line.
-                "\\(total.+[[:digit:]]+ ?[kKMGTPEZY]?i?B?\n\\)?"
-                ;; We don't know in which order ".", ".." and "foo" appear.
-                (format
-                 "\\(.+ %s\\( ->.+\\)?\n\\)\\{%d\\}"
-                 (regexp-opt (directory-files tmp-name1))
-                 (length (directory-files tmp-name1)))))))
+           (let ((directory-files (directory-files tmp-name1)))
+             (with-temp-buffer
+               (insert-directory
+                (file-name-as-directory tmp-name1) "-al" nil 'full-directory-p)
+               (goto-char (point-min))
+               (should
+                (looking-at-p
+                 (concat
+                  ;; There might be a summary line.
+                  "\\(total.+[[:digit:]]+ ?[kKMGTPEZY]?i?B?\n\\)?"
+                  ;; We don't know in which order ".", ".." and "foo" appear.
+                  (format
+                   "\\(.+ %s\\( ->.+\\)?\n\\)\\{%d\\}"
+                   (regexp-opt directory-files)
+                   (length directory-files)))))))
 
            ;; Check error cases.
            (when (and (tramp--test-supports-set-file-modes-p)
@@ -4167,9 +4168,16 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
                      (file-attributes tmp-name1))
                     tramp-time-dont-know)
              (should
-              (tramp-compat-time-equal-p
-                (file-attribute-modification-time (file-attributes tmp-name1))
-               (seconds-to-time 1)))
+              (or (tramp-compat-time-equal-p
+                    (file-attribute-modification-time
+                    (file-attributes tmp-name1))
+                   (seconds-to-time 1))
+                  ;; Some remote machines cannot resolve seconds.
+                  ;; The return the modification time `(0 0).
+                  (tramp-compat-time-equal-p
+                    (file-attribute-modification-time
+                    (file-attributes tmp-name1))
+                   (seconds-to-time 0))))
              ;; Setting the time for not existing files shall fail.
              (should-error
               (set-file-times tmp-name2)
@@ -4186,10 +4194,16 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
                (with-no-warnings
                  (set-file-times tmp-name1 (seconds-to-time 1) 'nofollow)
                  (should
-                  (tramp-compat-time-equal-p
-                    (file-attribute-modification-time
-                    (file-attributes tmp-name1))
-                   (seconds-to-time 1)))))))
+                  (or (tramp-compat-time-equal-p
+                       (file-attribute-modification-time
+                        (file-attributes tmp-name1))
+                       (seconds-to-time 1))
+                      ;; Some remote machines cannot resolve seconds.
+                      ;; The return the modification time `(0 0).
+                      (tramp-compat-time-equal-p
+                       (file-attribute-modification-time
+                        (file-attributes tmp-name1))
+                       (seconds-to-time 0))))))))
 
        ;; Cleanup.
        (ignore-errors