Skip to content

Commit bb0b148

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 1974e65 commit bb0b148

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
@@ -2590,6 +2590,13 @@ int mingw_rename(const char *pold, const char *pnew)
25902590
return 0;
25912591
gle = GetLastError();
25922592

2593+
if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container()) {
2594+
/* Fall back to copy to destination & remove source */
2595+
if (CopyFileW(wpold, wpnew, FALSE) && !mingw_unlink(pold))
2596+
return 0;
2597+
gle = GetLastError();
2598+
}
2599+
25932600
/* revert file attributes on failure */
25942601
if (attrs != INVALID_FILE_ATTRIBUTES)
25952602
SetFileAttributesW(wpnew, attrs);

0 commit comments

Comments
 (0)