-
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
mingw_open_existing: handle directories better #5342
base: main
Are you sure you want to change the base?
Conversation
CreateFileW() requires FILE_FLAG_BACKUP_SEMANTICS to create a directory handle [1] and errors out with ERROR_ACCESS_DENIED without this flag. Fall back to accessing Directory handles this way. [1] https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories This fixes git-for-windows#5068 Signed-off-by: Matthias Aßhauer <[email protected]>
@@ -810,13 +810,24 @@ static int mingw_open_existing(const wchar_t *filename, int oflags, ...) | |||
&security_attributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |||
if (handle == INVALID_HANDLE_VALUE) { | |||
DWORD err = GetLastError(); | |||
if (err == ERROR_ACCESS_DENIED) { | |||
DWORD attrs = GetFileAttributesW(filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably also check GetFileAttributesW()
before the first CreateFileW()
and avoid calling CreateFileW()
twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current version is fine because it optimizes for the common case, avoiding the extra GetFileAttributesW()
& CreateFileW()
calls for the vast majority of calls.
@@ -810,13 +810,24 @@ static int mingw_open_existing(const wchar_t *filename, int oflags, ...) | |||
&security_attributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |||
if (handle == INVALID_HANDLE_VALUE) { | |||
DWORD err = GetLastError(); | |||
if (err == ERROR_ACCESS_DENIED) { | |||
DWORD attrs = GetFileAttributesW(filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current version is fine because it optimizes for the common case, avoiding the extra GetFileAttributesW()
& CreateFileW()
calls for the vast majority of calls.
It looks like t5616 has a newly-introduced flake now:
I've restarted the job. |
CreateFileW()
requiresFILE_FLAG_BACKUP_SEMANTICS
to create a directory handle and errors out withERROR_ACCESS_DENIED
without this flag. Fall back to accessing Directory handles this way.This fixes #5068