This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Unsupported provider

classification
Title: os.path.realpath on Windows does not follow symbolic links
Type: behavior Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: steve.dower Nosy List: Christian Åkerström, eric.smith, eryksun, ethan smith, ishimoto, jaraco, living180, miss-islington, ncdave4life, pablogsal, paul.moore, pitrou, steve.dower, stutzbach, takluyver, tim.golden, vstinner, zach.ware, Étienne Dupuis
Priority: normal Keywords: needs review, patch

Created on 2010-09-25 15:03 by stutzbach, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ntpath_fix_issue9949.zip ncdave4life, 2012-03-09 23:12 Python 3.2 fix for issue 9949
issue9949.tar.bz2 living180, 2012-04-15 18:52 Python 3.3 fix for issue #9949
issue9949-v2.tar.bz2 living180, 2012-04-16 01:11 Python 3.3 fix for issue #9949, version 2
issue9949-v3.patch living180, 2012-06-03 20:04 Python 3.3 fix for issue #9949, version 3 review
issue9949-v4.patch living180, 2015-02-09 15:38 Python 3.5 fix for issue #9949, version 4 review
Pull Requests
URL Status Linked Edit
PR 15287 closed steve.dower, 2019-08-14 20:07
PR 15367 merged miss-islington, 2019-08-21 20:43
PR 15369 merged steve.dower, 2019-08-21 21:59
PR 15376 merged steve.dower, 2019-08-21 23:46
Messages (33)
msg117374 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-25 15:03
In Lib/ntpath.py:

# realpath is a no-op on systems without islink support
realpath = abspath


However, Windows Vista and newer support symbolic links and other Python methods support them.

(noticed this through source code inspection; haven't actually tested it)
msg142585 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-08-20 23:56
The issue #12799 has been marked as a duplicate of this issue:
"From a look at the code, realpath() does not seem to resolve symlinks under Windows, even though we have the _getfinalpathname function to do that. Please indulge with me if I'm wrong :)"
msg155270 - (view) Author: Dave Burton (ncdave4life) Date: 2012-03-09 23:12
This is a patch for the os.path.realpath() bug under Windows,  http://bugs.python.org/issue9949  "os.path.realpath on Windows does not follow symbolic links"

ntpath.diff fixes the realpath() function to resolve symbolic links to their targets (tested under Windows 7).

Note: I tried to make the equivalent patch for Python 2.7, but it didn't work because the "from nt import _getfinalpathname" fails.
msg155371 - (view) Author: Dave Burton (ncdave4life) Date: 2012-03-11 03:15
It seems that the nt module is implemented in the posixmodule.c source file, and the Python 3 version contains the posix__getfinalpathname entry point, but the Python 2 version does not.

I presume that PyWin32 could also be used to work around this.  Too bad it isn't automatically included with Python:
http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/
msg155372 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2012-03-11 03:22
file, and the Python 3 version contains the posix__getfinalpathname entry
point, but the Python 2 version does not.
>
> I presume that PyWin32 could also be used to work around this.  Too bad
it isn't automatically included with Python:
> http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/

We can't use external packages in the standard library. If you're looking
for a Python which includes pywin32, ActiveState provides this.

I think we can just implement the function we need.
msg155376 - (view) Author: Dave Burton (ncdave4life) Date: 2012-03-11 04:03
Excellent!

The ntpath.py change is nearly identical in Python 2.7 to the change for Python 3.2.  The only difference is that instead of:

+        elif isinstance(path, bytes):
+            path = os.getcwdb()

It is:

+        elif isinstance(path, unicode):
+            path = os.getcwdu()
msg158353 - (view) Author: Daniel Harding (living180) * Date: 2012-04-15 18:52
I have attached a series of patches with (hopefully) provide more robust fix for this issue, against the Python 3.3 branch.  It handles both bytes and str objects, paths that do not actually exist on the filesystem, and removal of the '\\?\' prefix returned by _getfinalpathname, unless the supplied path had that prefix already.  A couple of the patches contain some separate infrastructure that could hopefully be used to simplify some of the other Windows code in posixmodule.c (One immediate possibility would be to combine the code provided in these patches with the symbolic-link resolution code in the Windows stat functions - there is quite a bit of duplication there that could be eliminated.)

One thing these patches do not address is resolving a broken symbolic link.  The Windows API function GetFinalPathNameByHandle does not handle this case (because CreateFile cannot be used to get a handle if the symbolic link is broken).  This functionality could be implemented by manually following the reparse points, but that would basically require reimplementing GetFinalPathNameByHandle.

Finally, this patch could be fairly easily backported to Python 3.2, but that shouldn't be done without careful consideration.  It changes the return value from os.path.realpath on Windows even when there are no symbolic links in the path (the returned value will have the actual casing as stored on the filesystem, instead of the casing supplied by the user).  I don't think it should be backported to Python 2.7, because that version, like all Python versions before Python 3.2 are unaware of symbolic links on Windows (e.g. lexists is the same function as exists).

The patches were generated using git (I use git-hg) - if that format is a problem, let me know and I can regenerate them.
msg158390 - (view) Author: Daniel Harding (living180) * Date: 2012-04-16 01:11
Uploading a new series of patches - they are all the same as the first set, except for 0006-Make-realpath-follow-symbolic-links-on-Windows.patch.  I realized that I could use os.readlink to handle broken symbolic links, so I changed the logic of os.path.realpath slightly to do that (including recursive symlink detection).
msg162231 - (view) Author: Daniel Harding (living180) * Date: 2012-06-03 20:04
The previous version of this patch did not handle bytes arguments correctly and could fail in conjunction with a non-ASCII compatible encoding.  Also, if the result was a UNC path, it was not being handled correctly (the returned value would have started with a single backslash, not two).  Version 3 of the patch fixes these issues.  I am also attaching a single, condensed patch as requested by the Lifecycle of a Patch devguide.  I can also provide a patch series as before if desired.
msg166197 - (view) Author: Atsuo Ishimoto (ishimoto) * Date: 2012-07-23 02:02
Yet another patch to support symlink on Windows.
msg223299 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-16 23:46
@Zach can you do a patch review on this as it's holding up #13837 ?
msg223801 - (view) Author: Atsuo Ishimoto (ishimoto) * Date: 2014-07-24 01:57
I have unlinked my patch since it doesn't looks correct now. Sorry for disturbing.
msg229059 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014-10-11 05:34
Daniel: It's taken two years, but I've reviewed your patch :).  There are a few things that need to be addressed, but the basic change looks pretty good.  If you're still interested in seeing this fixed, I look forward to reviewing an updated patch; otherwise, I'll try to pick this up myself soon.
msg235615 - (view) Author: Daniel Harding (living180) * Date: 2015-02-09 15:38
@Zach - thanks for the review.  Sorry that it has taken a few months to pick this issue back up.  Anyway, here is an updated patch.  It is pretty different than the previous patch, to the point that I would consider it a completely new patch.

Anyway, here's a basic rundown of what the patch contains:

Two functions in Modules/posixmodule.c were modified to handle bytes objects as well as str objects:  win_readlink and _getfinalpathname.  This was necessary to allow os.path.realpath() to continue returning bytes when supplied with bytes.  I know you said in your review that you didn't care about this because using bytes paths on Windows is deprecated, but I think it still important to maintain backwards compatibility.

A new implementation of realpath() was added to Lib\ntpath.py, used when _getfinalpathname is available (when _getfinalpathname is not available, realpath remains a synonym for abspath, as it was previously).  The logic here has been completely reworked and is roughly modeled on the realpath implementation from Lib\posixpath.py.

A number of tests were added to Lib\test\test_ntpath.py for realpath() functionality.  Three of the tests were based on realpath() tests from test_posixpath.py, but one is completely new:  test_realpath_broken_symlinks.

A note about improved Windows support was added to the documentation for realpath(), but no other doc changes have been made.

Anyway, feedback is welcome - I'd love to get this code in sufficient shape to see a working realpath() implementation for Windows land in Python.
msg275287 - (view) Author: Christian Åkerström (Christian Åkerström) Date: 2016-09-09 08:16
Any update on this? Would be great with a fix for python symlinks on Windows.
msg310567 - (view) Author: Étienne Dupuis (Étienne Dupuis) Date: 2018-01-24 07:13
Referenced here: https://stackoverflow.com/questions/43333640/python-os-path-realpath-for-symlink-in-windows.
msg349771 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-14 22:31
FYI, there's been some discussion of this on issue37834, as the issues quickly became conflated.

There's also issue14094 which is a dup of this one, but with a different patch.

---

To move the relevant discussion here, my current PR is basically the tests from the last attached patch here plus a simpler implementation for non-strict resolution.

Right now the big open question is how to deal with the \\?\ prefix. My last two commits will leave it alone if it was in the initial path, and otherwise strip it if the non-prefixed path resolves to the same path as the prefixed path (the _getfinalpathname always returns a prefixed path).

The downside of this is that any unresolvable symlinks (dangling links, cycles, etc.) will now be returned with the prefix, whereas previously they were being returned without any attempt to resolve them being made (not because they are invalid, but because the old code wasn't attempting to resolve anything at all).

I kinda feel like this is okay, but would appreciate any other opinions on the matter. The alternative is to always strip the prefix, which could make some valid paths become invalid (for example, the one in the new test_realpath_symlink_prefix).
msg349879 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-16 18:34
Another minor change worth calling out - I added a note to the docs that when a symlink cycle is detected, realpath() could return any member of the cycle, but does not guarantee which one.

For our test cases it's generally stable enough, but if you change the starting point (e.g. from absolute to relative path) then it can change the result. It seemed easier all round just to not guarantee anything about which member of the cycle will be returned, rather than determining the exact rules, reproducing them across all platforms, and documenting them.
msg350107 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-21 20:43
New changeset 75e064962ee0e31ec19a8081e9d9cc957baf6415 by Steve Dower in branch 'master':
bpo-9949: Enable symlink traversal for ntpath.realpath (GH-15287)
https://github.com/python/cpython/commit/75e064962ee0e31ec19a8081e9d9cc957baf6415
msg350109 - (view) Author: miss-islington (miss-islington) Date: 2019-08-21 21:09
New changeset c30c869e8dec5eefdee7977943ffa11a8e3c8d75 by Miss Islington (bot) in branch '3.8':
bpo-9949: Enable symlink traversal for ntpath.realpath (GH-15287)
https://github.com/python/cpython/commit/c30c869e8dec5eefdee7977943ffa11a8e3c8d75
msg350111 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-08-21 21:32
There are multiple failures on several buildbots after commit 75e064962ee0e31ec19a8081e9d9cc957baf6415 was merged:

BUILDBOT FAILURE REPORT
=======================

Builder name: AMD64 Windows7 SP1 3.x
Builder url: https://buildbot.python.org/all/#/builders/40/
Build url: https://buildbot.python.org/all/#/builders/40/builds/2886

Failed tests
------------

- test_realpath_curdir (test.test_ntpath.TestNtpath)

- test_unicode_in_batch_file (test.test_venv.BasicTest)


Test leaking resources
----------------------



Build summary
-------------

== Tests result: FAILURE then FAILURE ==

384 tests OK.

10 slowest tests:
- test_multiprocessing_spawn: 2 min 45 sec
- test_tools: 2 min 5 sec
- test_distutils: 1 min 50 sec
- test_tokenize: 1 min 41 sec
- test_concurrent_futures: 1 min 39 sec
- test_lib2to3: 1 min 14 sec
- test_mmap: 1 min 11 sec
- test_largefile: 1 min 8 sec
- test_asyncio: 1 min 4 sec
- test_io: 1 min 3 sec

2 tests failed:
    test_ntpath test_venv

33 tests skipped:
    test_curses test_dbm_gnu test_dbm_ndbm test_devpoll test_epoll
    test_fcntl test_fork1 test_gdb test_grp test_ioctl test_kqueue
    test_multiprocessing_fork test_multiprocessing_forkserver test_nis
    test_openpty test_ossaudiodev test_pipes test_poll test_posix
    test_pty test_pwd test_readline test_resource test_spwd
    test_syslog test_threadsignals test_tix test_tk test_ttk_guionly
    test_wait3 test_wait4 test_xxtestfuzz test_zipfile64

2 re-run tests:
    test_ntpath test_venv

Total duration: 13 min 17 sec


Tracebacks
----------

```traceback
Traceback (most recent call last):
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_venv.py", line 337, in test_unicode_in_batch_file
    out, err = check_output(
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_venv.py", line 42, in check_output
    raise subprocess.CalledProcessError(
subprocess.CalledProcessError: Command '['\\\\?\\C:\\Users\\Buildbot\\AppData\\Local\\Temp\\tmpsbwlxx8h\\\u03fc\u045e\u0422\u03bb\u0424\u0419\\Scripts\\activate.bat', '&', 'python_d.exe', '-c', 'print(0)']' returned non-zero exit status 1.


Traceback (most recent call last):
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_venv.py", line 337, in test_unicode_in_batch_file
    out, err = check_output(
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_venv.py", line 42, in check_output
    raise subprocess.CalledProcessError(
subprocess.CalledProcessError: Command '['\\\\?\\C:\\Users\\Buildbot\\AppData\\Local\\Temp\\tmpxl3ubg90\\\u03fc\u045e\u0422\u03bb\u0424\u0419\\Scripts\\activate.bat', '&', 'python_d.exe', '-c', 'print(0)']' returned non-zero exit status 1.


Traceback (most recent call last):
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_ntpath.py", line 210, in test_realpath_curdir
    tester("ntpath.realpath('/'.join(['.'] * 100))", expected)
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_ntpath.py", line 30, in tester
    raise TestFailed("%s should return: %s but returned: %s" \

```

Current builder status
----------------------

The builder is failing currently

Commits
-------

- bcc446f525421156fe693139140e7051d000592e

- 75e064962ee0e31ec19a8081e9d9cc957baf6415


Other builds with similar failures
----------------------------------

-  https://buildbot.python.org/all/#/builders/208/builds/279
-  https://buildbot.python.org/all/#/builders/12/builds/2985
-  https://buildbot.python.org/all/#/builders/12/builds/2986
-  https://buildbot.python.org/all/#/builders/219/builds/190
-  https://buildbot.python.org/all/#/builders/40/builds/2885
-  https://buildbot.python.org/all/#/builders/3/builds/3298
-  https://buildbot.python.org/all/#/builders/3/builds/3299

Steve, can you take a look?
msg350114 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-21 21:47
On it
msg350116 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-21 21:56
I suspect the relevant failure here (which is not listed in Pablo's post) is this one:

======================================================================
ERROR: test_realpath_curdir (test.test_ntpath.TestNtpath)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_ntpath.py", line 210, in test_realpath_curdir
    tester("ntpath.realpath('/'.join(['.'] * 100))", expected)
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_ntpath.py", line 30, in tester
    raise TestFailed("%s should return: %s but returned: %s" \
test.support.TestFailed: ntpath.realpath('/'.join(['.'] * 100)) should return: C:\buildbot.python.org\3.x.kloth-win64\build\build\test_python_5340\test_python_worker_1408 but returned: \\?\C:\buildbot.python.org\3.x.kloth-win64\build\build\test_python_5340\test_python_worker_1408\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.

The path being normalized is longer than MAX_PATH, which is clearly causing failures with Windows APIs as implemented on Windows 7.

I can add the normpath() call back in, which should remove all the dots before ever actually testing realpath() and get it back down under MAX_PATH. That won't help anyone using real long paths on Win7 though, but then again the only reason this test was passing before was because there was a normpath() call, so we're no worse off (apart from performance-wise).

The venv issues seem unrelated. I'll get the realpath one fixed first and then take a look at those once I've finished today's tasks.
msg350119 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-21 22:25
Okay, the venv break is related (and it should have broken more frequently).

The new realpath() implementation leaves the \\?\ prefix behind if the path doesn't exist, since that's the error you get when the path is longer than MAX_PATH and you're on a system that can't handle it.

I think the best fix is probably to strip the prefix if the file didn't exist at the start and still doesn't exist afterwards.
msg350120 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-21 22:25
And sorry, the test_ntpath traceback was half listed in Pablo's message, but was missing the critical lines :)
msg350135 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-21 23:45
New changeset 06be2c7f357d12249445e95def1fb708a087b357 by Steve Dower in branch 'master':
bpo-9949: Call normpath() in realpath() and avoid unnecessary prefixes (GH-15369)
https://github.com/python/cpython/commit/06be2c7f357d12249445e95def1fb708a087b357
msg350138 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-08-21 23:59
I'm tentatively reopening this issue for you to consider the following point, Steve.

A real path is not always the same as a final path. We can find code that does `relpath(realpath(target), realpath(start))` to compute the relative path to target for a symlink. The final path can't be relied on for this unless we always evaluate the symlink from the final path to `start`. In particular, it cannot be relied on if the relative path traverses a junction. 

What code like this needs from a realpath() implementation is a solid (real) path, not a final path. In other words, the caller wants a solidified form of `start` that can be used to compute the path to a target for a relative symlink, but one that works when accessed from `start`, not the final path of `start`. Generally this means resolving symlinks in the path, but not mount points. That's what Unix realpath() does, but of course there it's simpler because the only name surrogate in Unix is a symlink, which is never a mount point and never a directory.

Here's an example. In this first case "scripts" is a junction mount point that targets "C:/spam/etc/scripts":

    >>> eggs = r'C:\spam\dlls\eggs.dll'
    >>> scripts = r'C:\spam\scripts'

    >>> rel_eggs_right = os.path.relpath(eggs, scripts)
    >>> print(rel_eggs_right)
    ..\dlls\eggs.dll
    >>> os.symlink(rel_eggs_right, 'C:/spam/scripts/eggs_right.dll')
    >>> os.path.exists('C:/spam/scripts/eggs_right.dll')
    True

    >>> scripts_final = os.path._getfinalpathname(scripts)[4:]
    >>> print(scripts_final)
    C:\spam\etc\scripts
    >>> rel_eggs_wrong = os.path.relpath(eggs, scripts_final)
    >>> print(rel_eggs_wrong)
    ..\..\dlls\eggs.dll
    >>> os.symlink(rel_eggs_wrong, 'C:/spam/scripts/eggs_wrong.dll')
    >>> os.path.exists('C:/spam/scripts/eggs_wrong.dll')
    False

If we remove the junction and replace it with a 'soft' symlink that targets the same directory, then using the final path works, and using the given path no longer works.

    >>> print(os.readlink('C:/spam/scripts'))
    C:\spam\etc\scripts
    >>> scripts_final = os.path._getfinalpathname(scripts)[4:]
    >>> rel_eggs_right_2 = os.path.relpath(eggs, scripts_final)
    >>> print(rel_eggs_right_2)
    ..\..\dlls\eggs.dll
    >>> os.symlink(rel_eggs_right_2, 'C:/spam/scripts/eggs_right_2.dll')
    >>> os.path.exists('C:/spam/scripts/eggs_right_2.dll')
    True

    >>> rel_eggs_wrong_2 = os.path.relpath(eggs, scripts)
    >>> print(rel_eggs_wrong_2)
    ..\dlls\eggs.dll
    >>> os.symlink(rel_eggs_wrong_2, 'C:/spam/scripts/eggs_wrong_2.dll')
    >>> os.path.exists('C:/spam/scripts/eggs_wrong_2.dll')
    False

When the kernel traverses "scripts" as a soft link, it collapses to the target (i.e. "C:/spam/etc/scripts"), so our relative path that was computed from the final path is right in this case. On the other hand, if "scripts" is is a mount point (junction), it's a hard (solid) component. It does not collapse to the target (the kernel even checks the junction's security descriptor, which it does not do for a symlink), so ".." in the relative symlink traverses the junction component as if it were an actual directory.

What we need is an implementation of realpath("C:/spam/scripts") that returns "C:\\spam\\scripts" when "scripts" is a mount point and returns "C:\\spam\\etc\\scripts" when "scripts" is a symlink.

This means we need an implementation of realpath() that looks a lot like posixpath.realpath. Generally a mount point should be walked over like a directory, just as mount points are handled in Unix. The difference is that a mount point in Windows is allowed to target a symlink. (This is a design flaw; Unix doesn't allow it.) Since we need to know the target of a junction, we have to read the reparse point, until we hit a real directory target. As long as it targets another junction, it remains a hard component. As soon as it targets a symlink, however, it becomes a soft component that needs to be resolved. If the junction targets a name surrogate reparse point that we can't read, then our only option is to get a final path. This is dysfunctional. We should raise an exception for this case. Code can handle the exception and knowingly get a final path instead of a real path.

This also means we can't reliably compute a real path for a remote path (UNC) because we can't manually evaluate the target of a remote junction. A remote junction is meaningless to us. If we're evaluating a UNC path and reach a junction, we have to give up on a real path and settle for a final path. We can get a final path because that lets the kernel in the server talk to our kernel to resolve any combination of mount points (handled on the server side) and symlinks (handled on our side). This case should also raise an exception. Aware code can handle it by getting a real path and taking appropriate measures.
msg350139 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-22 00:17
> We can find code that does `relpath(realpath(target), realpath(start))` to compute the relative path to target for a symlink. 

> In other words, the caller wants a solidified form of `start` that can be used to compute the path to a target for a relative symlink, but one that works when accessed from `start`, not the final path of `start`. 

I don't know how common this scenario is, but I can certainly say that it's never worked on Windows. You'd also end up with a relative symlink in a _real_ directory somewhere (that the junction was pointing at) that is unable to reach `target`, because it's now being resolved against the wrong start.

Relative symlinks are nearly as evil as symlink loops :)

Given there is no POSIX concept of a "final" path, a real path is the closest analogy. If this is the quality of edge case where that happens to break down, I'm okay with leaving it broken.

(Similarly for the junction/symlink combination on remote systems. I don't see any way that POSIX emulation can properly support that, but it seems like the far more rare case - and I say this as someone whose employer *lives and breathes* unnecessarily complicated SMB shares ;) I've never seen this become an issue.)
msg350140 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-22 00:23
New changeset a50d2f7e199f3be60c70c1586ee60ec60bf36642 by Steve Dower in branch '3.8':
bpo-9949: Call normpath() in realpath() and avoid unnecessary prefixes (GH-15376)
https://github.com/python/cpython/commit/a50d2f7e199f3be60c70c1586ee60ec60bf36642
msg350142 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-08-22 00:33
> Aware code can handle it [the exception] by getting a real path and 
> taking appropriate measures.

That should be "by getting a final path".
msg350145 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-08-22 00:52
>> We can find code that does `relpath(realpath(target), 
>> realpath(start))` to compute the relative path to target 
>> for a symlink. 
>> ...
> I don't know how common this scenario is, but I can certainly 
> say that it's never worked on Windows. You'd also end up with a 
> relative symlink in a _real_ directory somewhere (that the 
> junction was pointing at) that is unable to reach `target`, 
> because it's now being resolved against the wrong start.

With ntpath.realpath == ntpath.abspath, it actually works fine for just junctions because in most cases a mount point in Windows should be handled simply as just a directory, not resolved as its target. Revisit my example. This is what I showed when "C:/spam/scripts" is a junction. It's only wrong if the junction targets a directory symlink -- a chimeric mount-point-link that NT has made the mistake of allowing. (The kernel developers should have known to disallow this when they introduced Unix-like symlinks. When evaluating a mount point that targets a symlink, or any name-surrogate reparse point, it should fail the call as an invalid reparse point. For simplicity and our sanity, a mount point should always have consistent semantics in path parsing as a hard component that behaves like a regular directory. Then we could *always* handle it as just a directory -- whether it's local or remote. They messed up badly, IMO.)
msg350149 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-08-22 01:06
At this point, I'm inclined to say let's wait and see what the 3.8.0b4 feedback looks like.

Given that WSL has been fudging the boundaries here and hasn't suffered as a result, I don't expect much of a problem (and this change does actually make realpath() consistent between Windows native and WSL, which is nice). But I'm definitely open to making changes to this again if it turns out we need to.
msg350178 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-08-22 09:39
It seems like Windows buildbots are back to green (fixed), thanks ;-)
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54158
2019-08-22 09:39:44vstinnersetnosy: + vstinner
messages: + msg350178
2019-08-22 01:06:21steve.dowersetstatus: open -> closed

messages: + msg350149
2019-08-22 00:52:38eryksunsetmessages: + msg350145
2019-08-22 00:33:32eryksunsetmessages: + msg350142
2019-08-22 00:23:41steve.dowersetmessages: + msg350140
2019-08-22 00:17:50steve.dowersetmessages: + msg350139
2019-08-22 00:00:00eryksunsetstatus: closed -> open

messages: + msg350138
2019-08-21 23:46:46steve.dowersetpull_requests: + pull_request15087
2019-08-21 23:45:05steve.dowersetmessages: + msg350135
2019-08-21 22:25:43steve.dowersetmessages: + msg350120
2019-08-21 22:25:08steve.dowersetmessages: + msg350119
2019-08-21 21:59:24steve.dowersetpull_requests: + pull_request15080
2019-08-21 21:56:48steve.dowersetmessages: + msg350116
2019-08-21 21:47:00steve.dowersetmessages: + msg350114
2019-08-21 21:38:52steve.dowersetassignee: steve.dower
2019-08-21 21:38:40steve.dowersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-08-21 21:32:08pablogsalsetnosy: + pablogsal
messages: + msg350111
2019-08-21 21:09:36miss-islingtonsetnosy: + miss-islington
messages: + msg350109
2019-08-21 20:43:21miss-islingtonsetpull_requests: + pull_request15078
2019-08-21 20:43:09steve.dowersetmessages: + msg350107
2019-08-16 18:34:39steve.dowersetmessages: + msg349879
2019-08-14 22:36:46vstinnersetnosy: - vstinner
2019-08-14 22:31:07steve.dowersetnosy: + eryksun

messages: + msg349771
versions: + Python 3.8, Python 3.9, - Python 3.6
2019-08-14 20:07:11steve.dowersetkeywords: + patch
pull_requests: + pull_request15011
2018-08-13 05:26:52berker.peksagunlinkissue13837 dependencies
2018-01-24 07:13:08Étienne Dupuissetnosy: + Étienne Dupuis
messages: + msg310567
2017-07-05 05:30:39ethan smithsetnosy: + ethan smith
2016-09-09 08:22:42BreamoreBoysetnosy: - BreamoreBoy
2016-09-09 08:16:00Christian Åkerströmsetnosy: + Christian Åkerström
messages: + msg275287
2015-12-12 16:39:21SilentGhostsetkeywords: + needs review, - patch
nosy: + paul.moore, steve.dower

components: + Windows
versions: + Python 3.6, - Python 3.5
2015-02-09 15:38:09living180setfiles: + issue9949-v4.patch

messages: + msg235615
2014-10-11 05:34:38zach.waresetmessages: + msg229059
versions: + Python 3.5, - Python 2.7, Python 3.3, Python 3.4
2014-10-01 17:09:44takluyversetnosy: + takluyver
2014-07-24 01:57:33ishimotosetmessages: + msg223801
2014-07-24 01:55:36ishimotosetfiles: - issue9949.patch
2014-07-17 13:58:08brian.curtinsetnosy: - brian.curtin
2014-07-16 23:46:44BreamoreBoysetnosy: + BreamoreBoy
messages: + msg223299
2013-11-05 21:13:29zach.waresetnosy: + zach.ware
stage: needs patch -> patch review

versions: + Python 3.4, - Python 3.2
2012-10-07 11:09:22hyneklinkissue13837 dependencies
2012-07-23 02:02:15ishimotosetfiles: + issue9949.patch
nosy: + ishimoto
messages: + msg166197

2012-06-03 20:04:49living180setfiles: + issue9949-v3.patch
keywords: + patch
messages: + msg162231
2012-04-16 01:11:39living180setfiles: + issue9949-v2.tar.bz2

messages: + msg158390
2012-04-15 18:52:37living180setfiles: + issue9949.tar.bz2
nosy: + living180
messages: + msg158353

2012-03-11 04:03:25ncdave4lifesetmessages: + msg155376
2012-03-11 03:22:49brian.curtinsetmessages: + msg155372
2012-03-11 03:15:13ncdave4lifesetmessages: + msg155371
2012-03-09 23:12:06ncdave4lifesetfiles: + ntpath_fix_issue9949.zip
nosy: + ncdave4life
messages: + msg155270

2011-08-20 23:56:12vstinnersetnosy: + pitrou, tim.golden, vstinner

messages: + msg142585
versions: + Python 2.7, Python 3.3
2010-09-25 15:03:13stutzbachcreate