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

I apologize I missed this issue when it arose, so my comments come late.

The reason for inferring the directory status of the targets was so that use of 
os.symlink(link, target) would behave much the same on Unix as on Windows for 
the most common use cases. By requiring the directory status to be supplied 
when calling os.symlink, it makes the function barely portable (it becomes only 
portable for symlinks to files, not directories).

As was indicated by Larry Hastings in issue14917, there's an expectation that 
Python could easily detect the directory status of the target. There was 
apparently a bug in the earlier detection code for directories, which doesn't 
exist in the [reference 
implementation](https://bitbucket.org/jaraco/jaraco.windows/src/2.7/jaraco/windows/filesystem/__init__.py#cl-46)
 (done in ctypes):

PS C:\Users\jaraco\projects\jaraco.windows> mkdir -p Lib/test/foo
PS C:\Users\jaraco\projects\jaraco.windows> python
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from jaraco.windows import filesystem as fs
>>> fs.symlink('.\\test', 'Lib/bar')
>>> import os
>>> os.listdir('Lib/bar')
['foo']

I suspect this bug crept in as we worked through the various challenges with 
directory detection at that low level of Python. As you can see, the reference 
implementation is clean an straightforward and correct.

In my opinion, it would be worthwhile restoring the directory detection and 
creating tests to capture cases where detection fails, rather than removing the 
implementation.

I've been using the ctypes implementation for some time, and having automatic 
directory detection is a huge benefit to portability and simplicity of use.

It was pointed out that there is a race condition, and theoretically, that is 
true, but I believe this not to be a problem because the automatic detection is 
a best-effort. It's used to guess the best possible directory status for the 
symlink. If there's a directory there one millisecond, then the target is then 
removed, and the symlink is created as a directory symlink, that's most 
probably still what the user would have wanted.

As a heavy user of symlinks in Windows, I would strongly prefer inference of 
directory status. Of course, I can always continue to use the ctypes 
implementation in my environments, but I imagine that other potential users 
would feel the same as I do and would appreciate a more portable implementation.

Without the directory feature, many uses of os.symlink are not portable and 
will fail (with ugly results) on Windows. With the directory detection feature, 
most (if not all) will simply work as expected. Removal of this feature is a 
regression of the intended functionality, and I'd like it to be considered to 
be restored.

----------
nosy: +jason.coombs

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

Reply via email to