From 4e502a4997af4c8042a6ac13115a3f8ba31520ea Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 17 Apr 2024 12:58:19 +0300 Subject: gh-117394: Speed up os.path.ismount() on Posix (GH-117447) It is now 2-3 times faster if the user has permissions. --- Lib/posixpath.py | 9 ++++++--- .../next/Library/2024-04-02-11-17-44.gh-issue-117394.2aoSlb.rst | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-04-02-11-17-44.gh-issue-117394.2aoSlb.rst diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 11cbaca..79cda50 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 0000000..7b695be --- /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. -- cgit v0.12