]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117394: Speed up os.path.ismount() on Posix (GH-117447)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 17 Apr 2024 09:58:19 +0000 (12:58 +0300)
committerGitHub <noreply@github.com>
Wed, 17 Apr 2024 09:58:19 +0000 (12:58 +0300)
It is now 2-3 times faster if the user has permissions.

Lib/posixpath.py
Misc/NEWS.d/next/Library/2024-04-02-11-17-44.gh-issue-117394.2aoSlb.rst [new file with mode: 0644]

index 11cbaca53edb125467c6ea04d869995c6e49e130..79cda50753e0d201dcb8ac44fd88d487db093c53 100644 (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
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 (file)
index 0000000..7b695be
--- /dev/null
@@ -0,0 +1 @@
+:func:`os.path.ismount` is now 2-3 times faster if the user has permissions.