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 <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
ZCube authored and dscho committed Dec 17, 2024
1 parent 1c10ce3 commit 1e220c0
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 @@ -2738,6 +2738,13 @@ int mingw_rename(const char *pold, const char *pnew)
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 1e220c0

Please sign in to comment.