summaryrefslogtreecommitdiffstats
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2019-10-03 15:31:03 (GMT)
committerGitHub <noreply@github.com>2019-10-03 15:31:03 (GMT)
commita0e3d27e4e3cb5b67e325df080fb18b70c2910cf (patch)
tree53315214f83bc774e1c9dc1e0ab1887527208205 /Lib/ntpath.py
parent098e25672f1c3578855d5ded4f5147795c9ed956 (diff)
downloadcpython-a0e3d27e4e3cb5b67e325df080fb18b70c2910cf.zip
cpython-a0e3d27e4e3cb5b67e325df080fb18b70c2910cf.tar.gz
cpython-a0e3d27e4e3cb5b67e325df080fb18b70c2910cf.tar.bz2
bpo-38355: Fix ntpath.realpath failing on sys.executable (GH-16551)
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py20
1 files changed, 9 insertions, 11 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 01f1f42..d4ecff9 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -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, 1920, 1921
# 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