Subject: Re: bug#29149: Tramp shell uses local shell setting in windows

From: Michael Albinus <[email-masked]>
Date: Fri, 17 Nov 2017 15:53:09 +0100

Shuguang Sun <[email-masked]> writes:

> Hi Michael,

Hi Shuguang,

> I attached the trace log which has actions: open the file
> coxph_bench.r, and edit it, and save it. If you need the full log,
> please let me know.

Thanks!

I'll show the most interesting lines here, which tell us the flow

======================================================================
1 -> (tramp-file-name-handler find-backup-file-name "/plink:[email-masked]:/opt/home/username/test/coxph_bench.r")

The function `find-backup-file-name' has called the Tramp file name
handler due to the remote nature of the file name.

| 2 -> (tramp-sh-file-name-handler find-backup-file-name "/plink:[email-masked]:/opt/home/username/test/coxph_bench.r")
| | 3 -> (tramp-handle-find-backup-file-name "/plink:[email-masked]:/opt/home/username/test/coxph_bench.r")

Some Tramp internal flow in order to find the correct funtion. It is
`tramp-handle-find-backup-file-name'.

| | | 4 -> (tramp-run-real-handler find-backup-file-name ("/plink:[email-masked]:/opt/home/username/test/coxph_bench.r"))

`tramp-handle-find-backup-file-name' calls again
`find-backup-file-name', but suppressing file name handlers. This is
intended in order to ensure proper encoding of "/", ":" "!" and alike.

| | | | 5 -> (tramp-file-name-handler file-exists-p "/plink:[email-masked]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles")
| | | | 5 <- tramp-file-name-handler: t

Some other file name operations are called in `find-backup-file-name',
which work fine. I've removed them from the trace. The last such
operation is `file-exists-p'.

| | | | 5 -> (tramp-file-name-handler expand-file-name "/[email-masked]!/opt/home/username/test/coxph_bench.r" "/plink:[email-masked]:/opt/home/username/test/")

`find-backup-file-name' has finished the encoding of the file name (it
is "/[email-masked]!/opt/home/username/test/coxph_bench.r").
Due to the encoding, it looks like a local file name.

Now, `expand-file-name' is called with the encoded file name. Due to the
leading "/", it is regarded as absolute file name. Tramp is involved due
to the remote default-directory.

| | | | 5 <- tramp-file-name-handler: "c:/[email-masked]!/opt/home/username/test/coxph_bench.r"

... And this is the problem. Since Tramp sees the local absolute file,
it doesn't do anything, but let the default `expand-file-name' do the
job. This prefixes the file name with "c:/".

The rest is not surprising. The leading "c:" is transformed into
"!drive_c!", and here we are.

| | | | 5 -> (tramp-file-name-handler expand-file-name "[email-masked]!!!opt!bee!home_nas!username!test!coxph_bench.r" "/plink:[email-masked]:~/.emacs.d/backup-tramp/Rfiles")
| | | | 5 <- tramp-file-name-handler: "/plink:[email-masked]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/[email-masked]!!!opt!bee!home_nas!username!test!coxph_bench.r"
| | | | 5 -> (tramp-file-name-handler expand-file-name "/plink:[email-masked]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/" nil)
| | | | 5 -> (tramp-file-name-handler file-name-all-completions "[email-masked]!!!opt!bee!home_nas!username!test!coxph_bench.r.~" "/plink:[email-masked]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/")
| | | | 5 <- tramp-file-name-handler: ("[email-masked]!!!opt!bee!home_nas!username!test!coxph_bench.r.~1~")
| | | 4 <- tramp-run-real-handler: ("/plink:[email-masked]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/[email-masked]!!!opt!bee!home_nas!username!test!coxph_bench.r.~2~")
| | 3 <- tramp-handle-find-backup-file-name: ("/plink:[email-masked]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/[email-masked]!!!opt!bee!home_nas!username!test!coxph_bench.r.~2~")
| 2 <- tramp-sh-file-name-handler: ("/plink:[email-masked]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/[email-masked]!!!opt!bee!home_nas!username!test!coxph_bench.r.~2~")
1 <- tramp-file-name-handler: ("/plink:[email-masked]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/[email-masked]!!!opt!bee!home_nas!username!test!coxph_bench.r.~2~")

I have no clue yet how to fix. Pls give me some days to think about.

Best regards, Michael.