Skip to content

gh-117394: Reduce syscalls for posixpath.ismount #117395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,9 @@ def ismount(path):
if stat.S_ISLNK(s1.st_mode):
return False

path = os.fspath(path)
if isinstance(path, bytes):
parent = join(path, b'..')
else:
parent = join(path, '..')
parent = realpath(parent)
parent = dirname(abspath(path))
try:
s2 = os.lstat(parent)
s2 = os.stat(parent)
except (OSError, ValueError):
return False

Expand Down
8 changes: 6 additions & 2 deletions Lib/test/test_posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def test_ismount_symlinks(self):
def test_ismount_different_device(self):
# Simulate the path being on a different device from its parent by
# mocking out st_dev.
save_stat = os.stat
save_lstat = os.lstat
def fake_lstat(path):
st_ino = 0
Expand All @@ -251,15 +252,17 @@ def fake_lstat(path):
st_ino = 1
return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
try:
os.lstat = fake_lstat
os.stat = os.lstat = fake_lstat
self.assertIs(posixpath.ismount(ABSTFN), True)
finally:
os.stat = save_stat
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_stat = os.stat
save_lstat = os.lstat
def fake_lstat(path):
st_ino = 0
Expand All @@ -273,9 +276,10 @@ def fake_lstat(path):
st_ino = 1
return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
try:
os.lstat = fake_lstat
os.stat = os.lstat = fake_lstat
self.assertIs(posixpath.ismount(ABSTFN), True)
finally:
os.stat = save_stat
os.lstat = save_lstat

def test_isjunction(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speedup :func:`os.path.ismount` on Unix systems by reducing the number of
syscalls.