From 0e0b5e9ff840b6a26a0ad798ad68c07209c527b4 Mon Sep 17 00:00:00 2001 From: Ron Yorston <rmy@pobox.com> Date: Thu, 9 Oct 2014 14:35:36 +0100 Subject: mingw.c: ignore EACCES from mkdir if directory exists Microsoft Windows has a strange issue with access permissions such that mkdir will sometimes return EACESS for an existing directory. This is mentioned here: http://www.apijunkie.com/APIJunkie/blog/post/2009/12/22/_mkdir-C-runtime-library-function-might-return-unexpected-error-values.aspx This was causing mkdir -p to fail on a particular machine. Ignoring the EACCES error if the directory exists fixes the problem. --- win32/mingw.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'win32') diff --git a/win32/mingw.c b/win32/mingw.c index 8045fb996..dfdbecc85 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -762,7 +762,20 @@ const char *get_busybox_exec_path(void) #undef mkdir int mingw_mkdir(const char *path, int mode UNUSED_PARAM) { - return mkdir(path); + int ret; + struct stat st; + int lerrno = 0; + + if ( (ret=mkdir(path)) < 0 ) { + lerrno = errno; + if ( lerrno == EACCES && stat(path, &st) == 0 ) { + ret = 0; + lerrno = 0; + } + } + + errno = lerrno; + return ret; } int fcntl(int fd, int cmd, ...) -- cgit v1.2.3-55-g6feb