diff options
| author | Karsten Blees <karsten.blees@gmail.com> | 2026-01-09 20:05:07 +0000 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-01-09 18:32:55 -0800 |
| commit | ac41bfa374d67023970b26dc7117c878dfb58d06 (patch) | |
| tree | 698d7a32b3125e8d1f39a3cc4d55f332d20cbf5d /compat | |
| parent | 9ac15c2ae3d4d7caf27444930f2e3d12a6eebee8 (diff) | |
| download | git-ac41bfa374d67023970b26dc7117c878dfb58d06.tar.xz | |
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>
Diffstat (limited to 'compat')
| -rw-r--r-- | compat/mingw.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/compat/mingw.c b/compat/mingw.c index 0e8807196f..b1cc30d0f1 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -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; |
