[issue1578269] Add os.link() and os.symlink() and os.path.islink() support for Windows

Jason R. Coombs report at bugs.python.org
Sun May 31 22:47:37 CEST 2009


Jason R. Coombs <jaraco at jaraco.com> added the comment:

I've completed another draft patch.  This new one separates the
implementation of lstat and stat for windows, the latter which traverses
symlinks for the target.

I've tested this.  It compiles and runs under Windows Vista.  It works
correctly with file symlinks.  It fails to correctly detect that a
directory symlink is a symlink.  This is due to the fact that Windows
symlinks can also be directories, and the os.islink which calls
stat.S_ISLNK doesn't mask out the directory bit when checking for
symlinkness.

I see a few possible solutions:

1) Change S_ISLNK to mask of the directory bit when in Windows.
2) Change os.islink to perform a different test when in Windows.
3) Change the implementation of win32_lstat and win32_lstat_w to erase
the directory bit when the path is a link.

At first glance, option 3 seems the most promising, but it hides the
fact that Windows cares about the directoryness of a symlink.  It is
possible, for example, to have a "directory symlink" referring to a file
object in the file system.  S_ISDIR would be true for the symlink and
false for the target.

I think I'm going to implement approach 3 in a subsequent patch unless I
hear objections.

I also still need to implement Martin's two suggestions (release
kernel32 handle, inline functions).

But I wanted to share this patch for any suggestions.

----------
Added file: http://bugs.python.org/file14130/windows symlink draft 4.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1578269>
_______________________________________


More information about the Python-bugs-list mailing list