[Python-checkins] cpython (3.5): #2466: ismount now recognizes mount points user can't access.

r.david.murray python-checkins at python.org
Thu Aug 18 21:35:27 EDT 2016


https://hg.python.org/cpython/rev/cbc78ca21977
changeset:   102745:cbc78ca21977
branch:      3.5
parent:      102740:ba45fbb16499
user:        R David Murray <rdmurray at bitdance.com>
date:        Thu Aug 18 21:27:48 2016 -0400
summary:
  #2466: ismount now recognizes mount points user can't access.

Patch by Robin Roth, reviewed by Serhiy Storchaka, comment wording
tweaked by me.

files:
  Lib/posixpath.py           |   1 +
  Lib/test/test_posixpath.py |  24 ++++++++++++++++++++++--
  Misc/ACKS                  |   1 +
  Misc/NEWS                  |   3 +++
  4 files changed, 27 insertions(+), 2 deletions(-)


diff --git a/Lib/posixpath.py b/Lib/posixpath.py
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -193,6 +193,7 @@
         parent = join(path, b'..')
     else:
         parent = join(path, '..')
+    parent = realpath(parent)
     try:
         s2 = os.lstat(parent)
     except OSError:
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -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 @@
         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")
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1258,6 +1258,7 @@
 Just van Rossum
 Hugo van Rossum
 Saskia van Rossum
+Robin Roth
 Clement Rouault
 Donald Wallace Rouse II
 Liam Routt
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,9 @@
 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

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list