aboutsummaryrefslogtreecommitdiff
path: root/compat/mingw.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2011-02-07 21:54:01 +0100
committerJunio C Hamano <gitster@pobox.com>2011-02-07 15:45:54 -0800
commitab1a11be7858e1f92ee2e4ee1d70fabe7d5fe0ee (patch)
treee1fc25e4c4da01c522fe5e614d6c218da032e1b9 /compat/mingw.c
parent4f288100ceed14c65a1e964b2db4aaee4f4199fc (diff)
downloadgit-ab1a11be7858e1f92ee2e4ee1d70fabe7d5fe0ee.tar.gz
git-ab1a11be7858e1f92ee2e4ee1d70fabe7d5fe0ee.tar.xz
mingw_rmdir: set errno=ENOTEMPTY when appropriate
On Windows, EACCES overrules ENOTEMPTY when calling rmdir(). But if the directory is busy, we only want to retry deleting the directory if it is empty, so test specifically for that case and set ENOTEMPTY rather than EACCES. Noticed by Greg Hazel. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/mingw.c')
-rw-r--r--compat/mingw.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index e55c3cac7..878b1de97 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -225,6 +225,30 @@ int mingw_unlink(const char *pathname)
return ret;
}
+static int is_dir_empty(const char *path)
+{
+ struct strbuf buf = STRBUF_INIT;
+ WIN32_FIND_DATAA findbuf;
+ HANDLE handle;
+
+ strbuf_addf(&buf, "%s\\*", path);
+ handle = FindFirstFileA(buf.buf, &findbuf);
+ if (handle == INVALID_HANDLE_VALUE) {
+ strbuf_release(&buf);
+ return GetLastError() == ERROR_NO_MORE_FILES;
+ }
+
+ while (!strcmp(findbuf.cFileName, ".") ||
+ !strcmp(findbuf.cFileName, ".."))
+ if (!FindNextFile(handle, &findbuf)) {
+ strbuf_release(&buf);
+ return GetLastError() == ERROR_NO_MORE_FILES;
+ }
+ FindClose(handle);
+ strbuf_release(&buf);
+ return 0;
+}
+
#undef rmdir
int mingw_rmdir(const char *pathname)
{
@@ -233,6 +257,10 @@ int mingw_rmdir(const char *pathname)
while ((ret = rmdir(pathname)) == -1 && tries < ARRAY_SIZE(delay)) {
if (!is_file_in_use_error(GetLastError()))
break;
+ if (!is_dir_empty(pathname)) {
+ errno = ENOTEMPTY;
+ break;
+ }
/*
* We assume that some other process had the source or
* destination file open at the wrong moment and retry.