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 <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Nov 16, 2014 at 22:06 UTC ba6fad02b6cbbfbf5acf3303b4d8ddfd8624fdb2
1 file changed +1 -1
compat/mingw.c
+1 -1
@@ -312,7 +312,7 @@ int mingw_open (const char *filename, int oflags, ...)
312 return -1;
313 fd = _wopen(wfilename, oflags, mode);
314
315 - if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) {
315 + if (fd < 0 && (oflags & O_ACCMODE) != O_RDONLY && errno == EACCES) {
316 DWORD attrs = GetFileAttributesW(wfilename);
317 if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
318 errno = EISDIR;