Skip to content

Commit

Permalink
mingw: when running in a Windows container, try to rename() harder
Browse files Browse the repository at this point in the history
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 <zcube@zcube.kr>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
ZCube authored and dscho committed Sep 22, 2022
1 parent 65e654e commit 3e5a5c4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compat/mingw.c
Expand Up @@ -2535,6 +2535,13 @@ int mingw_rename(const char *pold, const char *pnew)
return 0;
gle = GetLastError();

if (gle == ERROR_ACCESS_DENIED && is_inside_windows_container()) {
/* Fall back to copy to destination & remove source */
if (CopyFileW(wpold, wpnew, FALSE) && !mingw_unlink(pold))
return 0;
gle = GetLastError();
}

/* revert file attributes on failure */
if (attrs != INVALID_FILE_ATTRIBUTES)
SetFileAttributesW(wpnew, attrs);
Expand Down

0 comments on commit 3e5a5c4

Please sign in to comment.