Alexey Izbyshev <izbys...@ispras.ru> added the comment:

Copying the comment of @eryksun from PR 6010 for reference.

Because we only try VOLUME_NAME_DOS, this function always fails for a volume 
that's not mounted as either a drive letter or a junction mount point. The 
error in this case is ERROR_PATH_NOT_FOUND. We know that the path is valid 
because we have a handle (in this case the file system ensures that no parent 
directory in the path can be unlinked or renamed). To address this, if the 
flags parameter isn't already VOLUME_NAME_GUID, it could switch to it and 
continue the while loop (no need to realloc). Otherwise if it's already 
VOLUME_NAME_GUID or for any other error, the call should fail.

For DOS devices in paths (e.g. "C:\Temp\NUL"), CreateFile commonly succeeds, 
but GetFinalPathNameByHandle commonly fails with either ERROR_INVALID_FUNCTION 
or ERROR_INVALID_PARAMETER. What do you think about handling this failure by 
calling GetFullPathName instead (e.g. "C:\Temp\NUL" => "\\.\NUL")? That way 
most DOS device paths won't cause this function to fail (e.g. when called by 
pathlib's resolve method). We could do the same if CreateFile fails with 
ERROR_INVALID_PARAMETER, which should only occur for CON (e.g. "C:\Temp\CON") 
because it needs to be opened with either generic read or generic write access.

CreatFile also commonly fails here with either ERROR_SHARING_VIOLATION (from a 
paging file) or ERROR_ACCESS_DENIED. But I think those are best handled by the 
caller, with a PermissionError exception handler. Currently pathlib's resolve 
method doesn't handle PermissionError like I think it should in non-strict 
mode. It only handles FileNotFoundError

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33016>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to