Skip to content

Commit fdd4fe4

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 8a681ee commit fdd4fe4

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
@@ -283,6 +283,13 @@ int mingw_unlink(const char *pathname)
283283
return 0;
284284
if (!is_file_in_use_error(GetLastError()))
285285
break;
286+
/*
287+
* _wunlink() / DeleteFileW() for directory symlinks fails with
288+
* ERROR_ACCESS_DENIED (EACCES), so try _wrmdir() as well. This is the
289+
* same error we get if a file is in use (already checked above).
290+
*/
291+
if (!_wrmdir(wpathname))
292+
return 0;
286293
} while (retry_ask_yes_no(&tries, "Unlink of file '%s' failed. "
287294
"Should I try again?", pathname));
288295
return -1;

0 commit comments

Comments
 (0)