diff -r 51ac5f06dd04 -r 079aa525e506 Lib/ntpath.py --- a/Lib/ntpath.py Tue Jul 24 03:45:39 2012 -0700 +++ b/Lib/ntpath.py Sat Jul 28 18:29:02 2012 +0900 @@ -339,16 +339,12 @@ return False return True -# Is a path a mount point? Either a root (with or without drive letter) -# or an UNC path with at most a / or \ after the mount point. - +from nt import _getvolumepathname def ismount(path): - """Test whether a path is a mount point (defined as root of drive)""" - seps = _get_bothseps(path) - root, rest = splitdrive(path) - if root and root[0] in seps: - return (not rest) or (rest in seps) - return rest in seps + """Test whether a path is a mount point""" + path = path.replace(altsep, sep) + volume = _getvolumepathname(path) + return volume == path # Expand paths beginning with '~' or '~user'. diff -r 51ac5f06dd04 -r 079aa525e506 Lib/test/test_ntpath.py --- a/Lib/test/test_ntpath.py Tue Jul 24 03:45:39 2012 -0700 +++ b/Lib/test/test_ntpath.py Sat Jul 28 18:29:02 2012 +0900 @@ -256,6 +256,19 @@ # dialogs (#4804) 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.assertFalse(ntpath.ismount("c:")) + self.assertFalse(ntpath.ismount("C:")) + self.assertFalse(ntpath.ismount("\\\\.\\c:")) + self.assertFalse(ntpath.ismount(support.TESTFN)) + class NtCommonTest(test_genericpath.CommonTest): pathmodule = ntpath diff -r 51ac5f06dd04 -r 079aa525e506 Modules/posixmodule.c --- a/Modules/posixmodule.c Tue Jul 24 03:45:39 2012 -0700 +++ b/Modules/posixmodule.c Sat Jul 28 18:29:02 2012 +0900 @@ -3824,6 +3824,47 @@ else Py_RETURN_FALSE; } + +PyDoc_STRVAR(posix__getvolumepathname__doc__, +"Return volume mount point of the specified path."); + +/* A helper function for ismount on windows */ +static PyObject * +posix__getvolumepathname(PyObject *self, PyObject *args) +{ + PyObject *po, *result; + wchar_t *path, *mountpath=NULL; + size_t bufsize; + BOOL ret; + + if (!PyArg_ParseTuple(args, "U|:_getvolumepathname", &po)) + return NULL; + path = PyUnicode_AsUnicode(po); + if (path == NULL) + return NULL; + + /* Volume path should be shorter than entire path */ + bufsize = max(MAX_PATH, wcslen(path) * 2 * sizeof(wchar_t)+1); + mountpath = malloc(bufsize); + if (mountpath == NULL) + return PyErr_NoMemory(); + + Py_BEGIN_ALLOW_THREADS + ret = GetVolumePathNameW(path, mountpath, bufsize); + Py_END_ALLOW_THREADS + + if (!ret) { + result = win32_error_object("_getvolumepathname", po); + goto exit; + } + result = PyUnicode_FromWideChar(mountpath, wcslen(mountpath)); +exit: + free(mountpath); + return result; +} +/* end of posix__getvolumepathname */ + + #endif /* MS_WINDOWS */ PyDoc_STRVAR(posix_mkdir__doc__, @@ -11272,6 +11313,7 @@ {"_getfileinformation", posix__getfileinformation, METH_VARARGS, NULL}, {"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__}, {"_getdiskusage", win32__getdiskusage, METH_VARARGS, win32__getdiskusage__doc__}, + {"_getvolumepathname", posix__getvolumepathname, METH_VARARGS, posix__getvolumepathname__doc__}, #endif #ifdef HAVE_GETLOADAVG {"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__},