Skip to content

Commit 879e40f

Browse files
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 b21b54c commit 879e40f

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
@@ -1655,7 +1655,12 @@ int mingw_rename(const char *pold, const char *pnew)
16551655
if (gle == ERROR_ACCESS_DENIED &&
16561656
(attrs = GetFileAttributesW(wpnew)) != INVALID_FILE_ATTRIBUTES) {
16571657
if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
1658-
errno = EISDIR;
1658+
DWORD attrsold = GetFileAttributesW(wpold);
1659+
if (attrsold == INVALID_FILE_ATTRIBUTES ||
1660+
!(attrsold & FILE_ATTRIBUTE_DIRECTORY))
1661+
errno = EISDIR;
1662+
else if (!_wrmdir(wpnew))
1663+
goto repeat;
16591664
return -1;
16601665
}
16611666
if ((attrs & FILE_ATTRIBUTE_READONLY) &&

0 commit comments

Comments
 (0)