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 Feb 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 81dd006 commit 2d56f47
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
@@ -371,6 +371,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;

0 comments on commit 2d56f47

Please sign in to comment.