Author jaraco
Recipients amaury.forgeotdarc, eric.smith, giampaolo.rodola, jafo, jaraco, lemburg, loewis, nnorwitz, r.david.murray, swarren
Date 2009-10-23.22:08:27
SpamBayes Score 2.12098e-08
Marked as misclassified No
Message-id <1256335709.5.0.623925954933.issue1578269@psf.upfronthosting.co.za>
In-reply-to
Content
After some in-depth analysis, I determined the following:

1) The new symlink-aware os.stat has to find the target of a symlink to
properly function.
2) The previously-proposed patch uses GetFilenameByHandle in os.stat to
find the target, but this fails when a handle can't be obtained (such as
when a symlink points to pagefile.sys.
3) Explorer doesn't use GetFilenameByHandle. I used ProcMon to monitor
the API calls when it looks up the properties for a symlink to
pagefile.sys. It appears to use CreateFile and DeviceIoControl to trace
through the symlink chain.

So, I've written a proof of concept that determines a symlink target
using these API calls. The code is in jaraco.windows.filesystem at
https://svn.jaraco.com/jaraco/python/jaraco.windows/jaraco/windows/filesystem.py:trace_symlink_target
.  For convenience, I've pasted the most relevant code segments at
http://paste.turbogears.org/paste/122986 .

I'd like to get comments on this implementation before porting this to
the C code and adding it to the os.stat call. One of the aspects that
makes me uncomfortable is the fact that I have to call relpath between
each iteration.

I have tested this approach fairly thoroughly. It appears to work under
all circumstances (through multiple symlinks across drives and
ultimately pointing at pagefile.sys).

If no one can suggest a better approach, I plan to code this into the patch.
History
Date User Action Args
2009-10-23 22:08:29jaracosetrecipients: + jaraco, lemburg, loewis, nnorwitz, jafo, amaury.forgeotdarc, eric.smith, giampaolo.rodola, swarren, r.david.murray
2009-10-23 22:08:29jaracosetmessageid: <1256335709.5.0.623925954933.issue1578269@psf.upfronthosting.co.za>
2009-10-23 22:08:28jaracolinkissue1578269 messages
2009-10-23 22:08:27jaracocreate