Subject: bug#57044: 29.0.50; tramp-error: Reading directory: Permission denied, /scp:motorolausb:/storage/emulated/0/

From: Michael Albinus <[email-masked]>
Date: Mon, 15 Aug 2022 14:13:49 +0200

Michael Albinus <[email-masked]> writes:

Hi Jean,

Finally, I've been successful to install termux properly. That gives me
the understanding what happens.

> - Apply the needed settings, like
>
>   (setq tramp-verbose 10
>         tramp-connection-properties '(("ssh:motorola" "tmpdir" "/storage/emulated/0/tmp"))
>         tramp-remote-path '(...)
>         tramp-remote-process-environment '(...))
>
>> 07:10:57.056208 tramp-send-command (6) # while read d; do if test -x $d/ls && test -f $d/ls; then echo tramp_executable $d/ls; break; fi; done <<'b43631a7d2938506927af066a6b54cbc'
>> /sbin
>> b43631a7d2938506927af066a6b54cbc
>> 07:10:57.060465 tramp-wait-for-regexp (6) #
>> ///fc5b092ac8d0a3784e7c5443fffe4f12#$
>
> It searches only (!) in /sbin, and I don't know why.

This the problem, indeed. tramp-remote-path uses directories like
"/usr/bin". But in Termux, there is a prefix, and the directory is
"/data/data/com.termux/files/usr/bin". So we must add this prefix to all
file names in tramp-remote-path. I've fixed this by declaring
tramp-remote-path as connection-local variable. After calling "emacs -Q
-l tramp", all what I needed was

--8<---------------cut here---------------start------------->8---
(setq tramp-connection-properties
      '(("/ssh:Samsung-SM-G920F-Michael-Albinus:" "tmpdir" "~/tmp"))

(connection-local-set-profile-variables
 'tramp-connection-local-termux-profile
 `((tramp-remote-path
    . ,(mapcar
	(lambda (x)
	  (if (stringp x) (concat "/data/data/com.termux/files" x) x))
	(copy-tree tramp-remote-path)))))

(connection-local-set-profiles
 '(:application tramp :machine "Samsung-SM-G920F-Michael-Albinus")
 'tramp-connection-local-termux-profile)
--8<---------------cut here---------------end--------------->8---

"Samsung-SM-G920F-Michael-Albinus" is the name of my Android device, and
"~/tmp" the temporary directory I have created.

Would you like to try it?

>> Jean

Best regards, Michael.