mingw: handle symlinks to directories in `mingw_unlink()`
The `_wunlink()` and `DeleteFileW()` functions refuse to delete symlinks to directories on Windows; The error code would be `ERROR_ACCESS_DENIED` in that case. Take that error code as an indicator that we need to try `_wrmdir()` as well. In the best case, it will remove a symlink. In the worst case, it will fail with the same error code again. Signed-off-by: Karsten Blees <karsten.blees@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karsten Blees committed
Jan 9, 2026 at 20:05 UTC
ac41bfa374d67023970b26dc7117c878dfb58d06
1 file changed
+8
-1
compat/mingw.c
+8
-1
@@ -338,9 +338,16 @@ int mingw_unlink(const char *pathname, int handle_in_use_error)
338
return 0;
339
if (!is_file_in_use_error(GetLastError()))
340
break;
341
+ /*
342
+ * _wunlink() / DeleteFileW() for directory symlinks fails with
343
+ * ERROR_ACCESS_DENIED (EACCES), so try _wrmdir() as well. This is the
344
+ * same error we get if a file is in use (already checked above).
345
+ */
346
+ if (!_wrmdir(wpathname))
347
+ return 0;
348
+
349
if (!handle_in_use_error)
350
return -1;
343
-
351
} while (retry_ask_yes_no(&tries, "Unlink of file '%s' failed. "
352
"Should I try again?", pathname));
353
return -1;