gh-117394: Speed up os.path.ismount() on Posix (GH-117447)

It is now 2-3 times faster if the user has permissions.
This commit is contained in:
Serhiy Storchaka 2024-04-17 12:58:19 +03:00 committed by GitHub
parent 51132da0c4
commit 4e502a4997
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -206,11 +206,14 @@ def ismount(path):
parent = join(path, b'..')
else:
parent = join(path, '..')
parent = realpath(parent)
try:
s2 = os.lstat(parent)
except (OSError, ValueError):
return False
except OSError:
parent = realpath(parent)
try:
s2 = os.lstat(parent)
except OSError:
return False
# path/.. on a different device as path or the same i-node as path
return s1.st_dev != s2.st_dev or s1.st_ino == s2.st_ino

View File

@ -0,0 +1 @@
:func:`os.path.ismount` is now 2-3 times faster if the user has permissions.