Skip to content
Open
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
4 changes: 2 additions & 2 deletions Doc/library/os.path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ the :mod:`glob` module.)
i-node on the same device --- this should detect mount points for all Unix
and POSIX variants. It is not able to reliably detect bind mounts on the
same filesystem. On Linux systems, it will always return ``True`` for btrfs
subvolumes, even if they aren't mount points. On Windows, a drive letter root
and a share UNC are always mount points, and for any other path
subvolumes, even if they aren't mount points. On Windows, a existent drive
letter root and a share UNC are always mount points, and for any other path
``GetVolumePathName`` is called to see if it is different from the input path.

.. versionchanged:: 3.4
Expand Down
15 changes: 10 additions & 5 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,19 @@ def ismount(path):
path = abspath(path)
drive, root, rest = splitroot(path)
if drive and drive[0] in seps:
# Share path is a mount point if it conforms to UNC.
return not rest
if root and not rest:
return True

# Drive root is a mount point if it exists.
return exists(path)
if _getvolumepathname:
x = path.rstrip(seps)
y =_getvolumepathname(path).rstrip(seps)
return x.casefold() == y.casefold()
try:
# The path is a mount point if it's a mounted volume.
x = path.rstrip(seps)
y = _getvolumepathname(path).rstrip(seps)
return x.casefold() == y.casefold()
except (OSError, FileNotFoundError):
return False
else:
return False

Expand Down
38 changes: 25 additions & 13 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,19 +1354,31 @@ def test_sameopenfile(self):
ntpath.sameopenfile(-1, -1)

def test_ismount(self):
self.assertTrue(ntpath.ismount("c:\\"))
self.assertTrue(ntpath.ismount("C:\\"))
self.assertTrue(ntpath.ismount("c:/"))
self.assertTrue(ntpath.ismount("C:/"))
self.assertTrue(ntpath.ismount("\\\\.\\c:\\"))
self.assertTrue(ntpath.ismount("\\\\.\\C:\\"))

self.assertTrue(ntpath.ismount(b"c:\\"))
self.assertTrue(ntpath.ismount(b"C:\\"))
self.assertTrue(ntpath.ismount(b"c:/"))
self.assertTrue(ntpath.ismount(b"C:/"))
self.assertTrue(ntpath.ismount(b"\\\\.\\c:\\"))
self.assertTrue(ntpath.ismount(b"\\\\.\\C:\\"))
if sys.platform == "win32":
self.assertTrue(ntpath.ismount("c:\\"))
self.assertTrue(ntpath.ismount("C:\\"))
self.assertTrue(ntpath.ismount("c:/"))
self.assertTrue(ntpath.ismount("C:/"))
self.assertTrue(ntpath.ismount("\\\\.\\c:\\"))
self.assertTrue(ntpath.ismount("\\\\.\\C:\\"))

self.assertTrue(ntpath.ismount(b"c:\\"))
self.assertTrue(ntpath.ismount(b"C:\\"))
self.assertTrue(ntpath.ismount(b"c:/"))
self.assertTrue(ntpath.ismount(b"C:/"))
self.assertTrue(ntpath.ismount(b"\\\\.\\c:\\"))
self.assertTrue(ntpath.ismount(b"\\\\.\\C:\\"))

# Look for a non-existent drive letter that can be used to test
# behaviour of ismount().
for drive in "DEFGHIJKLMNOPQRSTUVWXYZ":
if not ntpath.exists(drive + ":\\"):
self.assertFalse(ntpath.ismount(drive + ":\\"))
self.assertFalse(ntpath.ismount(drive + ":\\NotExist"))
break
else:
if support.verbose:
print("No missing drive found to test 'ismount'")

with os_helper.temp_dir() as d:
self.assertFalse(ntpath.ismount(d))
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ Eugene Dvurechenski
Karmen Dykstra
Josip Dzolonga
Maxim Dzumanenko
Thomas Earp
Hans Eckardt
Rodolpho Eckhardt
Ulrich Eckhardt
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For Windows, os.path.ismount() now returns False for non-existent drive letter roots.
Loading