summaryrefslogtreecommitdiff
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorBrian Curtin <brian@python.org>2011-06-08 18:17:18 -0500
committerBrian Curtin <brian@python.org>2011-06-08 18:17:18 -0500
commit9c669ccc77c85eac245d460bab510a38b20d9a08 (patch)
tree067c0f49c9e1fd369765a12003b3f8bc502c7175 /Lib/ntpath.py
parent41c1910bb3229874a02c19ecd9189715b3ce501b (diff)
downloadcpython-git-9c669ccc77c85eac245d460bab510a38b20d9a08.tar.gz
Fix #11583. Changed os.path.isdir to use GetFileAttributes instead of os.stat.
By changing to the Windows GetFileAttributes API in nt._isdir we can figure out if the path is a directory without opening the file via os.stat. This has the minor benefit of speeding up os.path.isdir by at least 2x for regular files and 10-15x improvements were seen on symbolic links (which opened the file multiple times during os.stat). Since os.path.isdir is used in several places on interpreter startup, we get a minor speedup in startup time.
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index ec8a7ab237..2483ced7ff 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -672,3 +672,16 @@ except ImportError:
def sameopenfile(f1, f2):
"""Test whether two file objects reference the same file"""
return _getfileinformation(f1) == _getfileinformation(f2)
+
+
+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
+except ImportError:
+ from genericpath import isdir as _isdir
+
+def isdir(path):
+ return _isdir(path)