-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Use GetFinalPathNameByHandleW instead of GetLongPathNameW to get full path #606
Conversation
The string that is returned by |
I know that, thanks.
This is not a good explanation! It states something out of the blue, does not address any of my suggestions, and does not even try to explain why. |
b403b56
to
e71957e
Compare
Commit has been updated. |
Hrm. You could have left more work for me to analyze those data, but not much... |
... and I just realized that you also kept the information to yourself that the |
|
||
if (INIT_PROC_ADDR(GetFinalPathNameByHandleW)) { | ||
HANDLE hnd = CreateFileW(cwd, 0, | ||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
In the meantime I found reports that In all, I am much more reluctant about this change now. There just have been many unexpected issues with it which makes me expect more to come. And all of that for only an obscure use case where somebody works from within a directory whose parent directory they have no business listing. I prefer to have substantially less doubts about Pull Requests. Let's see whether you can dispel them. |
Are your doubts dispelled? |
No. In fact, now I am even more doubtful, because I would have at least expected you to come up with a link to authoritative documentation that states clearly what one can expect on which Windows versions. Now I am more certain than before that you did not look whether it works on all Windows versions we try to support, you probably just tested this patch in your setup and did not care whether it works elsewhere, too. I have been bitten too often in the past by accepting patches in too good faith only to find out that I was left with fixing users' broken setups. There are two ways forward with this Pull Request:
|
`GetLongPathName()` function may fail when it is unable to query the parent directory of a path component to determine the long name for that component. It happens, because of it uses `FindFirstFile()` function for each next short part of path. The `FindFirstFile()` requires `List Directory` and `Synchronize` desired access for a calling process. In case of lacking such permission for some part of path, the `GetLongPathName()` returns 0 as result and `GetLastError()` returns ERROR_ACCESS_DENIED. `GetFinalPathNameByHandle()` function can help in such cases, because it requires `Read Attributes` and `Synchronize` desired access to the target path only. The `GetFinalPathNameByHandle()` function was introduced on `Windows Server 2008/Windows Vista`. So we need to load it dynamically. `CreateFile()` parameters: `lpFileName` = path to the current directory `dwDesiredAccess` = 0 (it means `Read Attributes` and `Synchronize`) `dwShareMode` = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE (it prevents `Sharing Violation`) `lpSecurityAttributes` = NULL (default security attributes) `dwCreationDisposition` = OPEN_EXISTING (required to obtain a directory handle) `dwFlagsAndAttributes` = FILE_FLAG_BACKUP_SEMANTICS (required to obtain a directory handle) `hTemplateFile` = NULL (when opening an existing file or directory, `CreateFile` ignores this parameter) The string that is returned by `GetFinalPathNameByHandle()` function uses the \\?\ syntax. To skip the prefix and convert backslashes to slashes, the `normalize_ntpath()` mingw function will be used. Note: `GetFinalPathNameByHandle()` function returns a final path. It is the path that is returned when a path is fully resolved. For example, for a symbolic link named "C:\tmp\mydir" that points to "D:\yourdir", the final path would be "D:\yourdir". Signed-off-by: Anton Serbulov <[email protected]>
Commit has been updated. |
Thank you, @skvoboo this commit was a real pleasure to read and indeed managed to reinstate my trust in it, in particular because it simply cannot cause regressions due to handling only the case when it would have failed earlier. |
Use GetFinalPathNameByHandleW instead of GetLongPathNameW to get full path
Pull request for issue #598