]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#2466: ismount now recognizes mount points user can't access.
authorR David Murray <rdmurray@bitdance.com>
Fri, 19 Aug 2016 01:27:48 +0000 (21:27 -0400)
committerR David Murray <rdmurray@bitdance.com>
Fri, 19 Aug 2016 01:27:48 +0000 (21:27 -0400)
Patch by Robin Roth, reviewed by Serhiy Storchaka, comment wording
tweaked by me.

Lib/posixpath.py
Lib/test/test_posixpath.py
Misc/ACKS
Misc/NEWS

index 7bb4d5957b09391cf161092ad82d3403db11c9b4..d9f3f993dae0eb4f44f96157d399d32e2c9e8404 100644 (file)
@@ -193,6 +193,7 @@ def ismount(path):
         parent = join(path, b'..')
     else:
         parent = join(path, '..')
+    parent = realpath(parent)
     try:
         s2 = os.lstat(parent)
     except OSError:
index acf110204cf547867a354ad4e6213032dfb22fe8..0783c36b9f0225f65f8c11a3626df707728abe7a 100644 (file)
@@ -1,7 +1,5 @@
-import itertools
 import os
 import posixpath
-import sys
 import unittest
 import warnings
 from posixpath import realpath, abspath, dirname, basename
@@ -213,6 +211,28 @@ class PosixPathTest(unittest.TestCase):
         finally:
             os.lstat = save_lstat
 
+    @unittest.skipIf(posix is None, "Test requires posix module")
+    def test_ismount_directory_not_readable(self):
+        # issue #2466: Simulate ismount run on a directory that is not
+        # readable, which used to return False.
+        save_lstat = os.lstat
+        def fake_lstat(path):
+            st_ino = 0
+            st_dev = 0
+            if path.startswith(ABSTFN) and path != ABSTFN:
+                # ismount tries to read something inside the ABSTFN directory;
+                # simulate this being forbidden (no read permission).
+                raise OSError("Fake [Errno 13] Permission denied")
+            if path == ABSTFN:
+                st_dev = 1
+                st_ino = 1
+            return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
+        try:
+            os.lstat = fake_lstat
+            self.assertIs(posixpath.ismount(ABSTFN), True)
+        finally:
+            os.lstat = save_lstat
+
     def test_expanduser(self):
         self.assertEqual(posixpath.expanduser("foo"), "foo")
         self.assertEqual(posixpath.expanduser(b"foo"), b"foo")
index 150d37a3a322fabf6ac966a89c87fb1d250eff05..0664e87265923d0b2c065d5b9ffc4edc86c2d0d7 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1258,6 +1258,7 @@ Guido van Rossum
 Just van Rossum
 Hugo van Rossum
 Saskia van Rossum
+Robin Roth
 Clement Rouault
 Donald Wallace Rouse II
 Liam Routt
index 6c78a191e24675848d3a01fae2323a343a909562..974bf1a8628d18f79fa1a9795f2cdc9fde2b62dd 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #2466: posixpath.ismount now correctly recognizes mount points which
+  the user does not have permission to access.
+
 - Issue #27773: Correct some memory management errors server_hostname in _ssl.wrap_socket().
 
 - Issue #26750: unittest.mock.create_autospec() now works properly for