summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 47e35cab3f..a14cc393ce 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -7235,12 +7235,21 @@ static int
wunlink(const WCHAR *path)
{
int ret = 0;
+ const DWORD SYMLINKD = FILE_ATTRIBUTE_REPARSE_POINT|FILE_ATTRIBUTE_DIRECTORY;
RUBY_CRITICAL({
const DWORD attr = GetFileAttributesW(path);
- if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
- SetFileAttributesW(path, attr & ~FILE_ATTRIBUTE_READONLY);
+ if (attr == (DWORD)-1) {
+ }
+ else if ((attr & SYMLINKD) == SYMLINKD) {
+ ret = RemoveDirectoryW(path);
+ }
+ else {
+ if (attr & FILE_ATTRIBUTE_READONLY) {
+ SetFileAttributesW(path, attr & ~FILE_ATTRIBUTE_READONLY);
+ }
+ ret = DeleteFileW(path);
}
- if (!DeleteFileW(path)) {
+ if (!ret) {
errno = map_errno(GetLastError());
ret = -1;
if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {