-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
os.path.ismount on windows doesn't support windows mount points #53281
Comments
On unices, ismount checks whether the given path is a mount point. Long story short, Python simply returns False when doing ismount(r"c:\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.. |
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? |
All we need to do is check the FILE_ATTRIBUTE_REPARSE_POINT Is there a case for adding an "attributes" function to os.path |
... 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. |
I see that ismount like function on windows is provide by the various If Windows supported is added to ismount function itself, then it might be But for posix, how will it be different from details provided by stat? Or would it be better to provide file attributes as part of stat |
I think we're saying the same thing :) The simplest thing to do here is to create a win_ismount function The wider issue of exposing GetFileAttributesW, eg under one of the On 22/06/2010 11:46, Senthil Kumaran wrote:
|
I'd like to add the win_ismount function mentioned by Tim. Is anyone else working on this presently? |
Sijin, please go ahead and submit a patch. No one is working on this at the moment. |
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(ur"c:\temp\test_c_mount"))
'0x410'
# normal directory
>>> hex(windll.kernel32.GetFileAttributesW(ur"c:\temp\orig"))
'0x10'
# link (created via mklink /d c:\temp\orig c:\temp\here2
>>> hex(windll.kernel32.GetFileAttributesW(ur"c:\temp\here2"))
'0x410' On futher searching - I found the following link: So the function ismount will need to do the following |
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 |
We can't depend on stuff from pywin32, but we could expose GetVolumePathName ourselves. |
Patch to expose GetVolumePathName() and implementation of ismount(). |
Unfortunately this missed the boat for 3.3; I'll target 3.4 when we've got a branch to commit to. |
Hi Tim, Yes, this would be great to get sorted out. Right now this makes no nense because of windows. cheers - chris |
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. |
bpo-9035.2.patch is an updated version of Atsuo's patch. Known issues:
|
bpo-9035.3.patch has switched to the new memory management API and has This approach does introduce a behavioural change: the root of a SUBSTed I think the simplest thing is to special-case drive roots (which are |
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. |
New changeset f283589cb71e by Tim Golden in branch 'default': |
New changeset 5258c4399f2e by Tim Golden in branch 'default': |
Fixed. Thanks for the patch |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: