From 838c34f81ce31752ad01898e6546f0c3a767dbaa Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Thu, 15 Mar 2012 20:37:26 +0100 Subject: [PATCH] Win32: fix detection of empty directories in is_dir_empty On Windows XP (not Win7), directories cannot be deleted while a find handle is open, causing "Deletion of directory '...' failed. Should I try again?" prompts. Prior to 19d1e75d "Win32: Unicode file name support (except dirent)", these failures were silently ignored due to strbuf_free in is_dir_empty resetting GetLastError to ERROR_SUCCESS. Close the find handle in is_dir_empty so that git doesn't block deletion of the directory even after all other applications have released it. Reported-by: John Chen Signed-off-by: Karsten Blees --- compat/mingw.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 36899908ee..e6f331a581 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -243,8 +243,11 @@ static int is_dir_empty(const wchar_t *wpath) while (!wcscmp(findbuf.cFileName, L".") || !wcscmp(findbuf.cFileName, L"..")) - if (!FindNextFileW(handle, &findbuf)) - return GetLastError() == ERROR_NO_MORE_FILES; + if (!FindNextFileW(handle, &findbuf)) { + DWORD err = GetLastError(); + FindClose(handle); + return err == ERROR_NO_MORE_FILES; + } FindClose(handle); return 0; } -- 2.11.4.GIT