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 24, 2024
1 parent 410c9d4 commit 0c61ae8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -2590,6 +2590,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 0c61ae8

Please sign in to comment.