Skip to content

Commit b146f9b

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 4b18f60 commit b146f9b

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
@@ -2037,6 +2037,13 @@ int mingw_rename(const char *pold, const char *pnew)
20372037
return 0;
20382038
gle = GetLastError();
20392039

2040+
if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container()) {
2041+
/* Fall back to copy to destination & remove source */
2042+
if (CopyFileW(wpold, wpnew, FALSE) && !mingw_unlink(pold))
2043+
return 0;
2044+
gle = GetLastError();
2045+
}
2046+
20402047
/* revert file attributes on failure */
20412048
if (attrs != INVALID_FILE_ATTRIBUTES)
20422049
SetFileAttributesW(wpnew, attrs);

0 commit comments

Comments
 (0)