Skip to content

Commit 93c88f0

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 081b7f5 commit 93c88f0

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
@@ -2361,6 +2361,13 @@ int mingw_rename(const char *pold, const char *pnew)
23612361
return 0;
23622362
gle = GetLastError();
23632363

2364+
if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container()) {
2365+
/* Fall back to copy to destination & remove source */
2366+
if (CopyFileW(wpold, wpnew, FALSE) && !mingw_unlink(pold))
2367+
return 0;
2368+
gle = GetLastError();
2369+
}
2370+
23642371
/* revert file attributes on failure */
23652372
if (attrs != INVALID_FILE_ATTRIBUTES)
23662373
SetFileAttributesW(wpnew, attrs);

0 commit comments

Comments
 (0)