Skip to content

Commit bec7926

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 1339dcb commit bec7926

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compat/mingw.c

+7
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ int mingw_unlink(const char *pathname)
360360
return 0;
361361
if (!is_file_in_use_error(GetLastError()))
362362
break;
363+
/*
364+
* _wunlink() / DeleteFileW() for directory symlinks fails with
365+
* ERROR_ACCESS_DENIED (EACCES), so try _wrmdir() as well. This is the
366+
* same error we get if a file is in use (already checked above).
367+
*/
368+
if (!_wrmdir(wpathname))
369+
return 0;
363370
} while (retry_ask_yes_no(&tries, "Unlink of file '%s' failed. "
364371
"Should I try again?", pathname));
365372
return -1;

0 commit comments

Comments
 (0)