Skip to content

Commit 54f7c81

Browse files
nalladscho
authored andcommitted
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 72b7842 commit 54f7c81

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
@@ -1648,7 +1648,12 @@ int mingw_rename(const char *pold, const char *pnew)
16481648
if (gle == ERROR_ACCESS_DENIED &&
16491649
(attrs = GetFileAttributesW(wpnew)) != INVALID_FILE_ATTRIBUTES) {
16501650
if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
1651-
errno = EISDIR;
1651+
DWORD attrsold = GetFileAttributesW(wpold);
1652+
if (attrsold == INVALID_FILE_ATTRIBUTES ||
1653+
!(attrsold & FILE_ATTRIBUTE_DIRECTORY))
1654+
errno = EISDIR;
1655+
else if (!_wrmdir(wpnew))
1656+
goto repeat;
16521657
return -1;
16531658
}
16541659
if ((attrs & FILE_ATTRIBUTE_READONLY) &&

0 commit comments

Comments
 (0)