aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorMichael Droettboom <mdboom@gmail.com>2023-02-08 09:34:24 -0500
committerGitHub <noreply@github.com>2023-02-08 14:34:24 +0000
commit86ebd5c3fa9ac0fba3b651f1d4abfca79614af5f (patch)
tree4e1cce7fb2ddc9e9a0cc248a789ff3c1b8080ca0 /Lib/ntpath.py
parent3a88de7a0af00872d9d57e1d98bc2f035cb15a1c (diff)
downloadcpython-86ebd5c3fa9ac0fba3b651f1d4abfca79614af5f.tar.gz
cpython-86ebd5c3fa9ac0fba3b651f1d4abfca79614af5f.zip
gh-101196: Make isdir/isfile/exists faster on Windows (GH-101324)
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py27
1 files changed, 8 insertions, 19 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index f9ee8e02a57..e93a5e69600 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -276,19 +276,6 @@ def dirname(p):
"""Returns the directory component of a pathname"""
return split(p)[0]
-# Is a path a symbolic link?
-# This will always return false on systems where os.lstat doesn't exist.
-
-def islink(path):
- """Test whether a path is a symbolic link.
- This will always return false for Windows prior to 6.0.
- """
- try:
- st = os.lstat(path)
- except (OSError, ValueError, AttributeError):
- return False
- return stat.S_ISLNK(st.st_mode)
-
# Is a path a junction?
@@ -870,11 +857,13 @@ def commonpath(paths):
try:
- # The genericpath.isdir implementation uses os.stat and checks the mode
- # attribute to tell whether or not the path is a directory.
- # This is overkill on Windows - just pass the path to GetFileAttributes
- # and check the attribute from there.
- from nt import _isdir as isdir
+ # The isdir(), isfile(), islink() and exists() implementations in
+ # genericpath use os.stat(). This is overkill on Windows. Use simpler
+ # builtin functions if they are available.
+ from nt import _path_isdir as isdir
+ from nt import _path_isfile as isfile
+ from nt import _path_islink as islink
+ from nt import _path_exists as exists
except ImportError:
- # Use genericpath.isdir as imported above.
+ # Use genericpath.* as imported above
pass