tramp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch: use GNU readlink --canonicalize for file-truename when available


From: Julian Scheid
Subject: Patch: use GNU readlink --canonicalize for file-truename when available
Date: Thu, 6 Aug 2009 00:34:57 +1200

tramp-handle-file-truename's current logic will lead to a series of
"test -e" and "stat" calls on the remote host, one each for every
component of the path (in the simple case of a path that does not use
any symlinks, probably more for heavily symlinked paths.)

This can pose a significant overhead on slow connections especially
for deeply nested files.

The attached patch will try to use GNU readlink's --canonicalize
feature to do the same in a single remote call instead, regardless of
the file's nesting level. See readlink(1).

GNU readlink is not available on all platforms. For instance, Mac OS
X's readlink is not GNU and does not provide the --canonicalize flag.
However, on remote hosts where it is available, such as Linux hosts,
this should speed things up considerably. On other hosts this will
fall back to the current logic.

Caveats:

This might need better error handling for the case where readlink fails.

It should also be verified that this has indeed the same semantics as
file-truename. Since neither file-truename's nor GNU readlink's
behaviour is documented precisely this is unfortunately not easy to
do. Superficially they both appear to do the same thing, though.

Newer versions of GNU readlink appear to offer --canonicalize-existing
and --canonicalize-missing flags. My test system does not have these.
It is not entirely clear to me whether these might be preferable when
available. See http://linux.die.net/man/1/readlink

Note that for hosts that don't have GNU readlink things might be
optimized further by doing canonicalization in a single remote call
using a remote script such as
http://codesnippets.joyent.com/posts/show/2049 , or maybe something
like "python -c "import os; print(os.path.realpath('%s'))" where a
Python interpreter is available (Macs usually have a working one.)

Attachment: tramp-file-truename-readlink.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]