Skip to content

Commit 750018b

Browse files
committed
#2466: ismount now recognizes mount points user can't access.
Patch by Robin Roth, reviewed by Serhiy Storchaka, comment wording tweaked by me.
1 parent eec9331 commit 750018b

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

Lib/posixpath.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def ismount(path):
193193
parent = join(path, b'..')
194194
else:
195195
parent = join(path, '..')
196+
parent = realpath(parent)
196197
try:
197198
s2 = os.lstat(parent)
198199
except OSError:

Lib/test/test_posixpath.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import itertools
21
import os
32
import posixpath
4-
import sys
53
import unittest
64
import warnings
75
from posixpath import realpath, abspath, dirname, basename
@@ -213,6 +211,28 @@ def fake_lstat(path):
213211
finally:
214212
os.lstat = save_lstat
215213

214+
@unittest.skipIf(posix is None, "Test requires posix module")
215+
def test_ismount_directory_not_readable(self):
216+
# issue #2466: Simulate ismount run on a directory that is not
217+
# readable, which used to return False.
218+
save_lstat = os.lstat
219+
def fake_lstat(path):
220+
st_ino = 0
221+
st_dev = 0
222+
if path.startswith(ABSTFN) and path != ABSTFN:
223+
# ismount tries to read something inside the ABSTFN directory;
224+
# simulate this being forbidden (no read permission).
225+
raise OSError("Fake [Errno 13] Permission denied")
226+
if path == ABSTFN:
227+
st_dev = 1
228+
st_ino = 1
229+
return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
230+
try:
231+
os.lstat = fake_lstat
232+
self.assertIs(posixpath.ismount(ABSTFN), True)
233+
finally:
234+
os.lstat = save_lstat
235+
216236
def test_expanduser(self):
217237
self.assertEqual(posixpath.expanduser("foo"), "foo")
218238
self.assertEqual(posixpath.expanduser(b"foo"), b"foo")

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,7 @@ Guido van Rossum
12581258
Just van Rossum
12591259
Hugo van Rossum
12601260
Saskia van Rossum
1261+
Robin Roth
12611262
Clement Rouault
12621263
Donald Wallace Rouse II
12631264
Liam Routt

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Core and Builtins
3838
Library
3939
-------
4040

41+
- Issue #2466: posixpath.ismount now correctly recognizes mount points which
42+
the user does not have permission to access.
43+
4144
- Issue #27773: Correct some memory management errors server_hostname in _ssl.wrap_socket().
4245

4346
- Issue #26750: unittest.mock.create_autospec() now works properly for

0 commit comments

Comments
 (0)