Skip to content

Commit 0f1397a

Browse files
kbleesdscho
authored andcommitted
Win32: mingw_unlink: support symlinks to directories
_wunlink() / DeleteFileW() refuses to delete symlinks to directories. If _wunlink() fails with ERROR_ACCESS_DENIED, try _wrmdir() as well. Signed-off-by: Karsten Blees <[email protected]>
1 parent 6e19cdb commit 0f1397a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compat/mingw.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ int mingw_unlink(const char *pathname)
241241
return 0;
242242
if (!is_file_in_use_error(GetLastError()))
243243
break;
244+
/*
245+
* _wunlink() / DeleteFileW() for directory symlinks fails with
246+
* ERROR_ACCESS_DENIED (EACCES), so try _wrmdir() as well. This is the
247+
* same error we get if a file is in use (already checked above).
248+
*/
249+
if (!_wrmdir(wpathname))
250+
return 0;
244251
} while (retry_ask_yes_no(&tries, "Unlink of file '%s' failed. "
245252
"Should I try again?", pathname));
246253
return -1;

0 commit comments

Comments
 (0)