From 417a71fe5c16121c85bf59c13f610ebcdf701508 Mon Sep 17 00:00:00 2001
From: "Erich E. Hoover" <erich.e.hoover@gmail.com>
Date: Sat, 30 Mar 2019 12:01:50 -0600
Subject: kernel32: Set error code when attempting to delete file symlinks as
 directories.

Signed-off-by: Erich E. Hoover <erich.e.hoover@gmail.com>
---
 dlls/kernel32/path.c    | 5 ++++-
 dlls/ntdll/tests/file.c | 6 +++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index 76a9512c77..f15b6dd68b 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -1738,7 +1738,10 @@ BOOL WINAPI RemoveDirectoryW( LPCWSTR path )
             ret = (unlink( unix_name.Buffer ) != -1);
         else
             ret = (rmdir( unix_name.Buffer ) != -1);
-        if (!ret) FILE_SetDosError();
+        if (status == STATUS_SUCCESS && (info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) &&
+                                        !(info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY))
+            SetLastError( ERROR_DIRECTORY );
+        else if (!ret) FILE_SetDosError();
         RtlFreeAnsiString( &unix_name );
     }
     else
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
index bacfad266e..2f5ee0618c 100644
--- a/dlls/ntdll/tests/file.c
+++ b/dlls/ntdll/tests/file.c
@@ -5071,9 +5071,9 @@ static void test_reparse_points(void)
     bret = RemoveDirectoryW(reparse_path);
     ok(!bret, "Succeeded in deleting file symlink as a directory!\n");
     err = GetLastError();
-    todo_wine ok(err == ERROR_DIRECTORY,
-                 "Expected last error 0x%x for RemoveDirectory on file symlink (actually 0x%x)!\n",
-                 ERROR_DIRECTORY, err);
+    ok(err == ERROR_DIRECTORY,
+       "Expected last error 0x%x for RemoveDirectory on file symlink (actually 0x%x)!\n",
+       ERROR_DIRECTORY, err);
     dwret = GetFileAttributesW(reparse_path);
     ok(dwret != (DWORD)~0, "Symlink doesn't exist (attributes: 0x%x)!\n", dwret);
     ok(dwret & FILE_ATTRIBUTE_REPARSE_POINT, "File is not a symlink! (attributes: 0x%x)\n", dwret);
-- 
2.17.1

