Skip to content

Commit 144d3ff

Browse files
ZCubemjcheetham
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 b5e62b7 commit 144d3ff

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
@@ -2571,6 +2571,13 @@ int mingw_rename(const char *pold, const char *pnew)
25712571
return 0;
25722572
gle = GetLastError();
25732573

2574+
if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container()) {
2575+
/* Fall back to copy to destination & remove source */
2576+
if (CopyFileW(wpold, wpnew, FALSE) && !mingw_unlink(pold))
2577+
return 0;
2578+
gle = GetLastError();
2579+
}
2580+
25742581
/* revert file attributes on failure */
25752582
if (attrs != INVALID_FILE_ATTRIBUTES)
25762583
SetFileAttributesW(wpnew, attrs);

0 commit comments

Comments
 (0)