Skip to content

Commit

Permalink
Win32: mingw_unlink: support symlinks to directories
Browse files Browse the repository at this point in the history
_wunlink() / DeleteFileW() refuses to delete symlinks to directories. If
_wunlink() fails with ERROR_ACCESS_DENIED, try _wrmdir() as well.

Signed-off-by: Karsten Blees <blees@dcon.de>
  • Loading branch information
kblees authored and dscho committed Sep 24, 2024
1 parent 93348ea commit fb3c384
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ int mingw_unlink(const char *pathname)
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;
} while (retry_ask_yes_no(&tries, "Unlink of file '%s' failed. "
"Should I try again?", pathname));
return -1;
Expand Down

0 comments on commit fb3c384

Please sign in to comment.