Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a0e3d27e
Commit
a0e3d27e
authored
Oct 03, 2019
by
Steve Dower
Committed by
GitHub
Oct 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-38355: Fix ntpath.realpath failing on sys.executable (GH-16551)
parent
098e2567
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
18 deletions
+15
-18
Lib/ntpath.py
Lib/ntpath.py
+9
-11
Lib/test/test_ntpath.py
Lib/test/test_ntpath.py
+5
-7
Misc/NEWS.d/next/Windows/2019-10-02-15-38-49.bpo-38355.n3AWX6.rst
...S.d/next/Windows/2019-10-02-15-38-49.bpo-38355.n3AWX6.rst
+1
-0
No files found.
Lib/ntpath.py
View file @
a0e3d27e
...
...
@@ -560,13 +560,6 @@ else:
return
path
def
_getfinalpathname_nonstrict
(
path
):
# Fast path to get the final path name. If this succeeds, there
# is no need to go any further.
try
:
return
_getfinalpathname
(
path
)
except
OSError
:
pass
# These error codes indicate that we should stop resolving the path
# and return the value we currently have.
# 1: ERROR_INVALID_FUNCTION
...
...
@@ -579,8 +572,9 @@ else:
# 67: ERROR_BAD_NET_NAME (implies remote server unavailable)
# 87: ERROR_INVALID_PARAMETER
# 123: ERROR_INVALID_NAME
# 1920: ERROR_CANT_ACCESS_FILE
# 1921: ERROR_CANT_RESOLVE_FILENAME (implies unfollowable symlink)
allowed_winerror
=
1
,
2
,
3
,
5
,
21
,
32
,
50
,
67
,
87
,
123
,
1921
allowed_winerror
=
1
,
2
,
3
,
5
,
21
,
32
,
50
,
67
,
87
,
123
,
192
0
,
192
1
# Non-strict algorithm is to find as much of the target directory
# as we can and join the rest.
...
...
@@ -615,9 +609,13 @@ else:
unc_prefix
=
'
\
\
\
\
?
\
\
UNC
\
\
'
new_unc_prefix
=
'
\
\
\
\
'
cwd
=
os
.
getcwd
()
did_not_exist
=
not
exists
(
path
)
had_prefix
=
path
.
startswith
(
prefix
)
path
=
_getfinalpathname_nonstrict
(
path
)
try
:
path
=
_getfinalpathname
(
path
)
initial_winerror
=
0
except
OSError
as
ex
:
initial_winerror
=
ex
.
winerror
path
=
_getfinalpathname_nonstrict
(
path
)
# The path returned by _getfinalpathname will always start with \\?\ -
# strip off that prefix unless it was already provided on the original
# path.
...
...
@@ -635,7 +633,7 @@ else:
except
OSError
as
ex
:
# If the path does not exist and originally did not exist, then
# strip the prefix anyway.
if
ex
.
winerror
in
{
2
,
3
}
and
did_not_exist
:
if
ex
.
winerror
==
initial_winerror
:
path
=
spath
return
path
...
...
Lib/test/test_ntpath.py
View file @
a0e3d27e
...
...
@@ -329,16 +329,14 @@ class TestNtpath(NtpathTestCase):
self.addCleanup(support.unlink, ABSTFN + "c")
self.addCleanup(support.unlink, ABSTFN + "a")
P = "
\
\
\
\
?
\
\
"
os.symlink(ABSTFN, ABSTFN)
self.assertPathEqual(ntpath.realpath(ABSTFN),
P +
ABSTFN)
self.assertPathEqual(ntpath.realpath(ABSTFN), ABSTFN)
# cycles are non-deterministic as to which path is returned, but
# it will always be the fully resolved path of one member of the cycle
os.symlink(ABSTFN + "1", ABSTFN + "2")
os.symlink(ABSTFN + "2", ABSTFN + "1")
expected = (
P + ABSTFN + "1", P +
ABSTFN + "2")
expected = (
ABSTFN + "1",
ABSTFN + "2")
self.assertPathIn(ntpath.realpath(ABSTFN + "1"), expected)
self.assertPathIn(ntpath.realpath(ABSTFN + "2"), expected)
...
...
@@ -357,14 +355,14 @@ class TestNtpath(NtpathTestCase):
expected)
os.symlink(ntpath.basename(ABSTFN) + "a
\
\
b", ABSTFN + "a")
self.assertPathEqual(ntpath.realpath(ABSTFN + "a"),
P +
ABSTFN + "a")
self.assertPathEqual(ntpath.realpath(ABSTFN + "a"), ABSTFN + "a")
os.symlink("..
\
\
" + ntpath.basename(ntpath.dirname(ABSTFN))
+ "
\
\
" + ntpath.basename(ABSTFN) + "c", ABSTFN + "c")
self.assertPathEqual(ntpath.realpath(ABSTFN + "c"),
P +
ABSTFN + "c")
self.assertPathEqual(ntpath.realpath(ABSTFN + "c"), ABSTFN + "c")
# Test using relative path as well.
self.assertPathEqual(ntpath.realpath(ntpath.basename(ABSTFN)),
P +
ABSTFN)
self.assertPathEqual(ntpath.realpath(ntpath.basename(ABSTFN)), ABSTFN)
@support.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, '
need
_getfinalpathname
')
...
...
Misc/NEWS.d/next/Windows/2019-10-02-15-38-49.bpo-38355.n3AWX6.rst
0 → 100644
View file @
a0e3d27e
Fixes ``ntpath.realpath`` failing on ``sys.executable``.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment