Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 94948aa

Browse files
kbleeskasal
authored andcommitted
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 19d1e75 "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 <[email protected]> Signed-off-by: Karsten Blees <[email protected]>
1 parent 80e6f0f commit 94948aa

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compat/mingw.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,11 @@ static int is_dir_empty(const wchar_t *wpath)
241241

242242
while (!wcscmp(findbuf.cFileName, L".") ||
243243
!wcscmp(findbuf.cFileName, L".."))
244-
if (!FindNextFileW(handle, &findbuf))
245-
return GetLastError() == ERROR_NO_MORE_FILES;
244+
if (!FindNextFileW(handle, &findbuf)) {
245+
DWORD err = GetLastError();
246+
FindClose(handle);
247+
return err == ERROR_NO_MORE_FILES;
248+
}
246249
FindClose(handle);
247250
return 0;
248251
}

0 commit comments

Comments
 (0)