Skip to content

Commit ecdf9f8

Browse files
kbleesGit for Windows Build Agent
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 1e93bbf commit ecdf9f8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

compat/mingw.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,16 @@ int mingw_unlink(const char *pathname, int handle_in_use_error)
372372
return 0;
373373
if (!is_file_in_use_error(GetLastError()))
374374
break;
375+
/*
376+
* _wunlink() / DeleteFileW() for directory symlinks fails with
377+
* ERROR_ACCESS_DENIED (EACCES), so try _wrmdir() as well. This is the
378+
* same error we get if a file is in use (already checked above).
379+
*/
380+
if (!_wrmdir(wpathname))
381+
return 0;
382+
375383
if (!handle_in_use_error)
376384
return -1;
377-
378385
} while (retry_ask_yes_no(&tries, "Unlink of file '%s' failed. "
379386
"Should I try again?", pathname));
380387
return -1;

0 commit comments

Comments
 (0)