Skip to content

Commit ba6fad0

Browse files
j6tgitster
authored andcommitted
Windows: correct detection of EISDIR in mingw_open()
According to the Linux open(2) man page, open() must return EISDIR if a directory was attempted to be opened for writing. Our emulation in mingw_open() does not get this right: it checks only for O_CREAT. Fix it to check for a write request. This fixes a failure in reflog handling, which opens files with O_APPEND|O_WRONLY, but without O_CREAT, and expects EISDIR when the named file happens to be a directory. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7fa1365 commit ba6fad0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

compat/mingw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ int mingw_open (const char *filename, int oflags, ...)
312312
return -1;
313313
fd = _wopen(wfilename, oflags, mode);
314314

315-
if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) {
315+
if (fd < 0 && (oflags & O_ACCMODE) != O_RDONLY && errno == EACCES) {
316316
DWORD attrs = GetFileAttributesW(wfilename);
317317
if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
318318
errno = EISDIR;

0 commit comments

Comments
 (0)