Subject: Re: bug#56342: TRAMP (sh) issues way too many commands, thus being very slow over high-ping networks

From: Michael Albinus <[email-masked]>
Date: Mon, 04 Jul 2022 12:33:39 +0200

Michael Albinus <[email-masked]> writes:

Hi Paul,

>> Suggested improvements:
>>
>> * TRAMP should issue just one `stat' command to find out most of the
>> things about a file: whether it exists, if it is a directory, its real
>> name when dereferencing links and whatever stats it is used to find
>> now; from `$ stat --help' this seems to be possible. In other words,
>> TRAMP shouldn't use simple commands like `test -e': any ping, even
>> nominal, will negate any gains from using a tad faster command.
>> Instead, if it needs to find anything about a file, it should ask the
>> remote about as many things as possible in one go: it is very likely
>> that the additional information will be needed soon and even if not,
>> this is basically free compared to ping anyway.
>
> Not all remote hosts carry a stat command, and not all existing stat's
> are GNU compatible. But yes, if possible, Tramp shall gather as much
> information in one run, and cache the results for further use.

FTR, stat is not sufficient to detect the real file name. Example:

# touch /tmp/a
# ln -s /tmp/a /tmp/b
# ln -s /tmp/b /tmp/c
# stat -c %N /tmp/c

It returns "'/tmp/c' -> '/tmp/b'". However, we need "/tmp/a". So we must
still use "readlink --canonicalize".

Best regards, Michael.