mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
gh-101196: Make isdir/isfile/exists faster on Windows (GH-101324)
Co-authored-by: Eryk Sun <eryksun@gmail.com>
This commit is contained in:
parent
3a88de7a0a
commit
86ebd5c3fa
9 changed files with 624 additions and 34 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue