diff options
author | Michael Droettboom <mdboom@gmail.com> | 2023-02-08 14:34:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-08 14:34:24 (GMT) |
commit | 86ebd5c3fa9ac0fba3b651f1d4abfca79614af5f (patch) | |
tree | 4e1cce7fb2ddc9e9a0cc248a789ff3c1b8080ca0 /Lib/genericpath.py | |
parent | 3a88de7a0af00872d9d57e1d98bc2f035cb15a1c (diff) | |
download | cpython-86ebd5c3fa9ac0fba3b651f1d4abfca79614af5f.zip cpython-86ebd5c3fa9ac0fba3b651f1d4abfca79614af5f.tar.gz cpython-86ebd5c3fa9ac0fba3b651f1d4abfca79614af5f.tar.bz2 |
gh-101196: Make isdir/isfile/exists faster on Windows (GH-101324)
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Diffstat (limited to 'Lib/genericpath.py')
-rw-r--r-- | Lib/genericpath.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/genericpath.py b/Lib/genericpath.py index ce36451..1bd5b38 100644 --- a/Lib/genericpath.py +++ b/Lib/genericpath.py @@ -7,7 +7,7 @@ import os import stat __all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime', - 'getsize', 'isdir', 'isfile', 'samefile', 'sameopenfile', + 'getsize', 'isdir', 'isfile', 'islink', 'samefile', 'sameopenfile', 'samestat'] @@ -45,6 +45,18 @@ def isdir(s): return stat.S_ISDIR(st.st_mode) +# 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""" + try: + st = os.lstat(path) + except (OSError, ValueError, AttributeError): + return False + return stat.S_ISLNK(st.st_mode) + + def getsize(filename): """Return the size of a file, reported by os.stat().""" return os.stat(filename).st_size |