Skip to content

Commit 66ee249

Browse files
nallanalla
authored and
nalla
committed
mingw: Try to delete target directory first.
When the rename function tries to move a directory it fails if the target directory exists. It should check if it can delete the (possibly empty) target directory and then try again to move the directory. Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: 마누엘 <[email protected]>
1 parent 9bab9e8 commit 66ee249

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compat/mingw.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,12 @@ int mingw_rename(const char *pold, const char *pnew)
15941594
if (gle == ERROR_ACCESS_DENIED &&
15951595
(attrs = GetFileAttributesW(wpnew)) != INVALID_FILE_ATTRIBUTES) {
15961596
if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
1597-
errno = EISDIR;
1597+
DWORD attrsold = GetFileAttributesW(wpold);
1598+
if (attrsold == INVALID_FILE_ATTRIBUTES ||
1599+
!(attrsold & FILE_ATTRIBUTE_DIRECTORY))
1600+
errno = EISDIR;
1601+
else if (!_wrmdir(wpnew))
1602+
goto repeat;
15981603
return -1;
15991604
}
16001605
if ((attrs & FILE_ATTRIBUTE_READONLY) &&

0 commit comments

Comments
 (0)