Skip to content

Commit 089577f

Browse files
ZCubeGit for Windows Build Agent
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 59062eb commit 089577f

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
@@ -2409,6 +2409,13 @@ int mingw_rename(const char *pold, const char *pnew)
24092409
return 0;
24102410
gle = GetLastError();
24112411

2412+
if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container()) {
2413+
/* Fall back to copy to destination & remove source */
2414+
if (CopyFileW(wpold, wpnew, FALSE) && !mingw_unlink(pold))
2415+
return 0;
2416+
gle = GetLastError();
2417+
}
2418+
24122419
/* revert file attributes on failure */
24132420
if (attrs != INVALID_FILE_ATTRIBUTES)
24142421
SetFileAttributesW(wpnew, attrs);

0 commit comments

Comments
 (0)