Steve Dower <steve.do...@python.org> added the comment:

> how could one write the `cmd.exe` `dir` command using Python?

I haven't checked, but if the dir command resolves the entire symlink chain 
rather than one step at a time, you'd use realpath (though that seems unlikely, 
tbh).

Failing that, you'd add extra logic to prepare the path for display to the 
user, and then you _would not_ use that prepared display path to resolve the 
link.

readlink() is intended for resolving links, not for displaying links. That's 
why it doesn't prepare them for display, but preserves the most accurate 
information possible. (We chose a more pragmatic route with realpath(), by 
checking that the nicer path resolves to the same target as the accurate one, 
and only then returning the nicer one.)

Really, for dir, you'd read the print name and display it when it's in the 
contents of the target. But you'd use the substitute name to resolve the target 
when "dir <symlink>" is called. We _could_ add a new API to Python for this, 
but it wouldn't be cross-platform and it doesn't solve a correctness issue, so 
we didn't. Feel free to request it, bearing in mind that it would be 
Windows-only (AFAIK).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40654>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to