FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-117394: Reduce syscalls for `posixpath.ismount` by nineteendo · Pull Request #117395 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 2 additions & 7 deletions Lib/posixpath.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Back | FazBrowse Home | New Git URL