From: Serhiy Storchaka Date: Wed, 17 Apr 2024 09:58:19 +0000 (+0300) Subject: gh-117394: Speed up os.path.ismount() on Posix (GH-117447) X-Git-Tag: v3.13.0b1~384 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4e502a4997af4c8042a6ac13115a3f8ba31520ea;p=thirdparty%2FPython%2Fcpython.git gh-117394: Speed up os.path.ismount() on Posix (GH-117447) It is now 2-3 times faster if the user has permissions. --- diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 11cbaca53edb..79cda50753e0 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -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 diff --git a/Misc/NEWS.d/next/Library/2024-04-02-11-17-44.gh-issue-117394.2aoSlb.rst b/Misc/NEWS.d/next/Library/2024-04-02-11-17-44.gh-issue-117394.2aoSlb.rst new file mode 100644 index 000000000000..7b695be4b35d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-04-02-11-17-44.gh-issue-117394.2aoSlb.rst @@ -0,0 +1 @@ +:func:`os.path.ismount` is now 2-3 times faster if the user has permissions.