]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mingw: handle symlinks to directories in `mingw_unlink()`
authorKarsten Blees <blees@dcon.de>
Wed, 17 Dec 2025 14:08:47 +0000 (14:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Dec 2025 23:22:18 +0000 (08:22 +0900)
The `_wunlink()` and `DeleteFileW()` functions refuse to delete symlinks
to directories on Windows; The error code woutl 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 <blees@dcon.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c

index 0e8807196fcbedef6618e32d0dd8826f5a4d6b32..b1cc30d0f13922291eea8215d667fba851e5efc2 100644 (file)
@@ -338,9 +338,16 @@ int mingw_unlink(const char *pathname, int handle_in_use_error)
                        return 0;
                if (!is_file_in_use_error(GetLastError()))
                        break;
+               /*
+                * _wunlink() / DeleteFileW() for directory symlinks fails with
+                * ERROR_ACCESS_DENIED (EACCES), so try _wrmdir() as well. This is the
+                * same error we get if a file is in use (already checked above).
+                */
+               if (!_wrmdir(wpathname))
+                       return 0;
+
                if (!handle_in_use_error)
                        return -1;
-
        } while (retry_ask_yes_no(&tries, "Unlink of file '%s' failed. "
                        "Should I try again?", pathname));
        return -1;