Skip to content

Commit 90aa2a7

Browse files
ZCubedscho
authored andcommitted
mingw: when running in a Windows container, try to rename() harder
It is a known issue that a rename() can fail with an "Access denied" error at times, when copying followed by deleting the original file works. Let's just fall back to that behavior. Signed-off-by: JiSeop Moon <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent e2e107e commit 90aa2a7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compat/mingw.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,13 @@ int mingw_rename(const char *pold, const char *pnew)
20532053
return 0;
20542054
gle = GetLastError();
20552055

2056+
if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container()) {
2057+
/* Fall back to copy to destination & remove source */
2058+
if (CopyFileW(wpold, wpnew, FALSE) && !mingw_unlink(pold))
2059+
return 0;
2060+
gle = GetLastError();
2061+
}
2062+
20562063
/* revert file attributes on failure */
20572064
if (attrs != INVALID_FILE_ATTRIBUTES)
20582065
SetFileAttributesW(wpnew, attrs);

0 commit comments

Comments
 (0)