From b9c65203d0f419306ac062e59a59643db9a1a541 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sat, 6 Aug 2022 18:09:35 +0200 Subject: [PATCH] Adapt Tramp for Android 12 * 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 | 16 ++++++++--- lisp/net/tramp.el | 8 +++++- test/lisp/net/tramp-tests.el | 56 ++++++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 26 deletions(-) diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 918de68ea9b..ed51628c4a7 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -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 diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index ae31287eced..4cc4ee0722e 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -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) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index e2d4ed781bb..e2cafc240b9 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -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 -- 2.39.2