[issue9035] os.path.ismount on windows doesn't support windows mount points
Roundup Robot added the comment: New changeset f283589cb71e by Tim Golden in branch 'default': Issue #9035: os.path.ismount now recognises volumes mounted below http://hg.python.org/cpython/rev/f283589cb71e -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Roundup Robot added the comment: New changeset 5258c4399f2e by Tim Golden in branch 'default': issue9035: Prevent Windows-specific tests from running on non-Windows platforms http://hg.python.org/cpython/rev/5258c4399f2e -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Tim Golden added the comment: Fixed. Thanks for the patch -- resolution: - fixed stage: needs patch - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Changes by Tim Golden m...@timgolden.me.uk: Removed file: http://bugs.python.org/file31092/issue9035.3.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Changes by Tim Golden m...@timgolden.me.uk: Removed file: http://bugs.python.org/file31087/issue9035.2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Tim Golden added the comment: 4th and hopefully final patch. Added tests for byte paths. Reworked the ismount so it uses the original detection approach first (which is wholly lexical) and drops back to the volume path technique only if the path doesn't appear to be a drive or a share root. This should minimise backwards-incompatibility while still solving the original problem. -- Added file: http://bugs.python.org/file31098/issue9035.4.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Tim Golden added the comment: I put a bit of work in on this this morning, following Mark's suggestion (msg138197) since that's the canonical approach. Unfortunately, it completely fails to work for the most common case: the root folder of a drive! The documentation for FindFirstFile explicitly precludes that possibility. It looks as though GetVolumePathName is the way to go. I thought I'd previously found some instance where that failed but, ad hoc, I can't make it fail now. I'll try to rework Atsuo's patch against the current posixmodule.c. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Tim Golden added the comment: issue9035.2.patch is an updated version of Atsuo's patch. Known issues: * I haven't reworked it for the new memory-management API * There's no test for a non-root mount point (which is really the basis for this issue). It's difficult to see how to do that in a robust way on an arbitrary machine without quite a bit of support machinery. I've done ad hoc tests which succeed. -- Added file: http://bugs.python.org/file31087/issue9035.2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Tim Golden added the comment: issue9035.3.patch has switched to the new memory management API and has tweaked the tests slightly for robustness. This approach does introduce a behavioural change: the root of a SUBSTed drive (essentially a symlink into the Dos namespace) will raise an OSError because GetVolumePathName returns error 87: invalid parameter. So os.path.ismount(F:\\) will fail where F: is the result of running, eg, SUBST F: C:\temp. I think the simplest thing is to special-case drive roots (which are always mount points) and then to apply the new GetVolumePathName logic. -- Added file: http://bugs.python.org/file31092/issue9035.3.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___diff --git a/Lib/ntpath.py b/Lib/ntpath.py --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -336,15 +336,26 @@ 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. +# or an UNC path with at most a / or \ after the mount point or a mounted +# drive. The canonical approach which detects the IO_REPARSE_TAG_MOUNT_POINT +# fails for drive roots. -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 +try: +from nt import _getvolumepathname +def ismount(path): +# +# GetVolumePathName will return the directory itself +# if it is a mount point (including a drive root). +# +return abspath(path).rstrip(sep) == abspath(_getvolumepathname(path)).rstrip(sep) +except ImportError: +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 # Expand paths beginning with '~' or '~user'. diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -256,6 +256,29 @@ # 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:\\)) + +with support.temp_dir() as d: +self.assertFalse(ntpath.ismount(d)) + +# +# Make sure the current folder isn't the root folder +# (or any other volume root). The drive-relative +# locations below cannot then refer to mount points +# +drive, path = ntpath.splitdrive(sys.executable) +with support.change_cwd(os.path.dirname(sys.executable)): +self.assertFalse(ntpath.ismount(drive.lower())) +self.assertFalse(ntpath.ismount(drive.upper())) + +self.assertTrue(ntpath.ismount(localhost\\c$)) +self.assertTrue(ntpath.ismount(localhost\\c$\\)) class NtCommonTest(test_genericpath.CommonTest, unittest.TestCase): pathmodule = ntpath diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -3711,6 +3711,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 = (wchar_t *)PyMem_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: +PyMem_Free(mountpath); +return result; +} +/* end of posix__getvolumepathname */ + #endif /* MS_WINDOWS */ PyDoc_STRVAR(posix_mkdir__doc__, @@ -10884,6 +10925,7 @@ {_getfinalpathname, posix__getfinalpathname, METH_VARARGS, NULL}, {_isdir,
[issue9035] os.path.ismount on windows doesn't support windows mount points
Christian Tismer added the comment: Hi Tim, Yes, this would be great to get sorted out. Then we could make watchdog.py automatically configure itself for network mounts. Right now this makes no nense because of windows. cheers - chris -- nosy: +Christian.Tismer ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Tim Golden added the comment: Unfortunately this missed the boat for 3.3; I'll target 3.4 when we've got a branch to commit to. -- versions: +Python 3.4 -Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Atsuo Ishimoto added the comment: Patch to expose GetVolumePathName() and implementation of ismount(). Tested on Windows7/XP. -- keywords: +patch Added file: http://bugs.python.org/file26558/issue9035.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Changes by Atsuo Ishimoto ishim...@gembook.org: -- nosy: +ishimoto ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Oren Held o...@held.org.il added the comment: Anything wrong with the following simple approach? (e.g. is it bad to depend on win32file?) def win_ismount(path): import win32file volume_path = win32file.GetVolumePathName(path) return volume_path == path # May have to ignore a trailing backslash -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Brian Curtin br...@python.org added the comment: We can't depend on stuff from pywin32, but we could expose GetVolumePathName ourselves. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Mark Mc Mahon mtnbikingm...@gmail.com added the comment: I was looking at this - and see that (at least as far as GetFileAttributes is concerned) that a mount and a linked directory are seen the same... Here are some tests using ctypes # mounted drive hex(windll.kernel32.GetFileAttributesW(urc:\temp\test_c_mount)) '0x410' # normal directory hex(windll.kernel32.GetFileAttributesW(urc:\temp\orig)) '0x10' # link (created via mklink /d c:\temp\orig c:\temp\here2 hex(windll.kernel32.GetFileAttributesW(urc:\temp\here2)) '0x410' On futher searching - I found the following link: http://msdn.microsoft.com/en-us/library/aa363940%28v=vs.85%29.aspx So the function ismount will need to do the following a) Get the file attributes b) check that it's a directory and is a reparse point c) Use FindFirstFile (and FindNextFile? - I need to test more) to fill in WIN32_FIND_DATA.dwResearved0 d) Check that against IO_REPARSE_TAG_MOUNT_POINT (0xA003) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Changes by Brian Curtin br...@python.org: -- nosy: +brian.curtin ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Senthil Kumaran sent...@uthcode.com added the comment: Sijin, please go ahead and submit a patch. No one is working on this at the moment. -- nosy: +markm ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Changes by Sijin Joseph sijinjos...@gmail.com: -- nosy: +sijinjoseph ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Sijin Joseph sijinjos...@gmail.com added the comment: I'd like to add the win_ismount function mentioned by Tim. Is anyone else working on this presently? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Changes by Santoso Wijaya santoso.wij...@gmail.com: -- nosy: +santa4nt versions: +Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Senthil Kumaran orsent...@gmail.com added the comment: I see that ismount like function on windows is provide by the various Win32 extensions. If Windows supported is added to ismount function itself, then it might be a good idea to have attributes or list_attributes function as well. But for posix, how will it be different from details provided by stat? Would not it add redundancy? Or would it be better to provide file attributes as part of stat itself (if some are missing in Windows). -- nosy: +orsenthil ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Tim Golden m...@timgolden.me.uk added the comment: I think we're saying the same thing :) The simplest thing to do here is to create a win_ismount function in posixmodule.c which does the attributes / reparse tag dance and returns True/False and use that wherever it's needed to support this concept under Windows. The current solution is correct for a subset of cases. Arguably a bug, although I doubt I'd get that past the release manager! The wider issue of exposing GetFileAttributesW, eg under one of the unused stat fields, should be explored elsewhere. On 22/06/2010 11:46, Senthil Kumaran wrote: Senthil Kumaranorsent...@gmail.com added the comment: I see that ismount like function on windows is provide by the various Win32 extensions. If Windows supported is added to ismount function itself, then it might be a good idea to have attributes or list_attributes function as well. But for posix, how will it be different from details provided by stat? Would not it add redundancy? Or would it be better to provide file attributes as part of stat itself (if some are missing in Windows). -- nosy: +orsenthil ___ Python trackerrep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/mail%40timgolden.me.uk -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
New submission from Oren Held o...@held.org.il: On unices, ismount checks whether the given path is a mount point. On windows, it only checks whether it's a drive letter. Long story short, Python simply returns False when doing ismount(rc:\mount1), while c:\mount1 is a real mount point. This is relevant for all modern windows versions. -- I'm using win32file.GetVolumePathName() for overcoming this, but I'm not sure if the os python package should be importing win32file, maybe there is a better way to check whether a path is a mount point.. -- components: Windows messages: 108225 nosy: Oren_Held priority: normal severity: normal status: open title: os.path.ismount on windows doesn't support windows mount points versions: Python 2.6, Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Tim Golden m...@timgolden.me.uk added the comment: Switching to Python 3.2 as this essentially constitutes a behaviour change and 2.6 is in bugfix mode and 2.7 is about to enter rc2. It would certainly be possible to use one of the volume APIs under the covers. Would you be willing to offer a patch to, say, posixmodule.c? -- assignee: - tim.golden nosy: +tim.golden stage: - needs patch type: - behavior versions: +Python 3.2 -Python 2.6, Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Tim Golden m...@timgolden.me.uk added the comment: All we need to do is check the FILE_ATTRIBUTE_REPARSE_POINT in the file attributes. Frustratingly, we grab file attributes a dozen times in posixpath.c only to throw most of it away. Is there a case for adding an attributes function to os.path which exposes the full file attributes on Windows, and its posix equivalent if there is one? This could then be used in the ismount function currently implemented in ntpath.py. -- title: os.path.ismount on windows doesn't support windows mount points - os.path.ismount on windows doesn't support windows mount points ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Tim Golden m...@timgolden.me.uk added the comment: ... of course you still need to get the reparse tag to determine whether this is a mount point so the file attributes alone in this case are not enough. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9035] os.path.ismount on windows doesn't support windows mount points
Changes by Giampaolo Rodola' g.rod...@gmail.com: -- nosy: +giampaolo.rodola ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9035 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com