Skip to content

Commit 88d2d4e

Browse files
jeffhostetlerGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
mingw: improve performance of mingw_unlink()
Update mingw_unlink() to first try to delete the file with existing permissions before trying to force it. Windows throws an error when trying to delete a read-only file. The mingw_unlink() compatibility wrapper always tries to _wchmod(666) the file before calling _wunlink() to avoid that error. However, since most files in the worktree are already writable, this is usually wasted effort. Update mingw_unlink() to just call DeleteFileW() directly and if that succeeds return. If that fails, fall back into the existing code path to update the permissions and use _wunlink() to get the existing error code mapping. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 112d9bc commit 88d2d4e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

compat/mingw.c

+3
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ int mingw_unlink(const char *pathname)
508508
if (xutftowcs_long_path(wpathname, pathname) < 0)
509509
return -1;
510510

511+
if (DeleteFileW(wpathname))
512+
return 0;
513+
511514
do {
512515
/* read-only files cannot be removed */
513516
_wchmod(wpathname, 0666);

0 commit comments

Comments
 (0)