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
normpath does not work with local literal paths #59491
Comments
Local literal paths are those paths that do use the \\?\ that allows to have paths longer that the MAX_PATH set by Windows (http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#short_vs.\_long_names). While UNC (http://en.wikipedia.org/wiki/Path_%28computing%29) paths should not be normalized, local paths that do use the \\?\ prefix should so that developers that use such a trink to allow longer paths on windows do not have to wrapp the call in the following way: LONG_PATH_PREFIX = '\\?\' The possible solution would be for the normalization to work and return the path normalized with the prefix added. |
Hi mandel :) With the exception of the "import string" inside of _get_letters (policy is to do all imports at the top), it looks ok just by reading. Assigning to myself to complete it after I return from holiday in a few days (unless someone beats me). |
I think this is wrong. The MSDN doc says: “Because it turns off automatic expansion of the path string, the "\\?\" prefix also allows the use of ".." and "." in the path names, which can be useful if you are attempting to perform operations on a file with these otherwise reserved relative path specifiers as part of the fully qualified path.” (from http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx#namespaces) So by "normalizing" the extended path, you are actually changing its meaning. Furthermore, normpath() is generally wrong in the face of symlinks, meaning it shouldn't be used at all. |
Antoine, What the MSDN is stating is that the Windows functions from COM will not normalize the path if it is prefixed by \\?\. That is, if a user wanted to do: path = r'\\?\C:\Users\mandel\..\Desktop\test'
with open(path, 'w') as fd:
fd.write('hello!') he will get the following: [Errorno 22] Invalid argument. r'\\?\C:\Users\mandel\..\Desktop\test' The same think would happen if a C function is used, that is, open is doing the right thing. On the other hand, the same code without the \\?\ works. This makes it even more important to allow the normpath users to normalize such paths, that is, a developer knows that the path has more than 260 chars and wants to make sure that the path can be written in the system: May I ask you why you mention the symbolic links? I know that if one of the segments of the path is a symbolic link there are problems but this is not related to \\?\ or am I confused? Just curious :) Brian, The ntpath module is a little mess (look at my other patch http://bugs.python.org/issue15275) and I think there are more performance problems hidden there somewhere... I imported string within the function because the same is done in expandvars (around line 430) and wanted to follow the style that was already in use in the file. I do agree that imports at the top are the way to go :) |
No, it is not related with "\\?\" but I'm pointing out that normpath() For the record, I'm trying to build a saner path-handling library at |
As Antoine's pathlib made it into 3.4 is the patch here now obsolete or what? Also note the reference to bpo-15275. |
As ntpath was cleaned up on bpo-15275 do we need this patch or not, especially given that pathlib made it into 3.4? |
This old issue still needs to be fixed. The check for special_prefixes in ntpath.normpath() must be removed in order to be consistent with WinAPI GetFullPathNameW(). In Windows, one can just call ntpath.abspath() to ensure that nt._getfullpathname() is called. But "Lib/ntpath.py" is cross-platform. |
I don't think the described behaviour is a bug, exactly because "\\?\" paths don't support virtual path elements like "." and ".." and "resolving" them from such a path would change the meaning. However, I think that would deserve a warning in the documentation. The code in ntpath.py actually explains what happens pretty well: # in the case of paths with these prefixes:
# \\.\ -> device names
# \\?\ -> literal paths
# do not do any normalization, but return the path
# unchanged apart from the call to os.fspath() |
I agree. Noting this in the docs should be fine - we shouldn't normalise something that's been explicitly marked as "not to be normalised" |
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: