Module: wine Branch: master Commit: f8699c0a71a528d287b84cd0bc5b5bb7cec924f0 URL: https://source.winehq.org/git/wine.git/?a=commit;h=f8699c0a71a528d287b84cd0b...
Author: Alexandre Julliard julliard@winehq.org Date: Wed Jul 8 12:47:46 2020 +0200
kernel32: Move RemoveDirectoryA/W() implementation to kernelbase.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/kernel32/kernel32.spec | 4 +-- dlls/kernel32/path.c | 62 ----------------------------------------- dlls/kernelbase/file.c | 44 +++++++++++++++++++++++++++++ dlls/kernelbase/kernelbase.spec | 4 +-- dlls/ntdll/tests/file.c | 3 +- 5 files changed, 50 insertions(+), 67 deletions(-)
diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec index b19dfa00df..0c64144d7f 100644 --- a/dlls/kernel32/kernel32.spec +++ b/dlls/kernel32/kernel32.spec @@ -1268,8 +1268,8 @@ @ stdcall ReleaseSemaphoreWhenCallbackReturns(ptr long long) ntdll.TpCallbackReleaseSemaphoreOnCompletion @ stdcall ReleaseSRWLockExclusive(ptr) ntdll.RtlReleaseSRWLockExclusive @ stdcall ReleaseSRWLockShared(ptr) ntdll.RtlReleaseSRWLockShared -@ stdcall RemoveDirectoryA(str) -@ stdcall RemoveDirectoryW(wstr) +@ stdcall -import RemoveDirectoryA(str) +@ stdcall -import RemoveDirectoryW(wstr) # @ stub RemoveLocalAlternateComputerNameA # @ stub RemoveLocalAlternateComputerNameW @ stdcall RemoveVectoredContinueHandler(ptr) ntdll.RtlRemoveVectoredContinueHandler diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c index db2c1fb024..d0f27d3359 100644 --- a/dlls/kernel32/path.c +++ b/dlls/kernel32/path.c @@ -228,68 +228,6 @@ BOOL WINAPI CreateDirectoryExA( LPCSTR template, LPCSTR path, LPSECURITY_ATTRIBU }
-/*********************************************************************** - * RemoveDirectoryW (KERNEL32.@) - */ -BOOL WINAPI RemoveDirectoryW( LPCWSTR path ) -{ - OBJECT_ATTRIBUTES attr; - UNICODE_STRING nt_name; - ANSI_STRING unix_name; - IO_STATUS_BLOCK io; - NTSTATUS status; - HANDLE handle; - BOOL ret = FALSE; - - TRACE( "%s\n", debugstr_w(path) ); - - if (!RtlDosPathNameToNtPathName_U( path, &nt_name, NULL, NULL )) - { - SetLastError( ERROR_PATH_NOT_FOUND ); - return FALSE; - } - attr.Length = sizeof(attr); - attr.RootDirectory = 0; - attr.Attributes = OBJ_CASE_INSENSITIVE; - attr.ObjectName = &nt_name; - attr.SecurityDescriptor = NULL; - attr.SecurityQualityOfService = NULL; - - if (!set_ntstatus( NtOpenFile( &handle, DELETE | SYNCHRONIZE, &attr, &io, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT ))) - { - RtlFreeUnicodeString( &nt_name ); - return FALSE; - } - - status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN ); - RtlFreeUnicodeString( &nt_name ); - if (!set_ntstatus( status )) - { - NtClose( handle ); - return FALSE; - } - - if (!(ret = (rmdir( unix_name.Buffer ) != -1))) FILE_SetDosError(); - RtlFreeAnsiString( &unix_name ); - NtClose( handle ); - return ret; -} - - -/*********************************************************************** - * RemoveDirectoryA (KERNEL32.@) - */ -BOOL WINAPI RemoveDirectoryA( LPCSTR path ) -{ - WCHAR *pathW; - - if (!(pathW = FILE_name_AtoW( path, FALSE ))) return FALSE; - return RemoveDirectoryW( pathW ); -} - - /*********************************************************************** * GetSystemDirectoryW (KERNEL32.@) * diff --git a/dlls/kernelbase/file.c b/dlls/kernelbase/file.c index bd87f75665..9d082f1a64 100644 --- a/dlls/kernelbase/file.c +++ b/dlls/kernelbase/file.c @@ -3448,6 +3448,50 @@ BOOL WINAPI DECLSPEC_HOTPATCH ReadFileScatter( HANDLE file, FILE_SEGMENT_ELEMENT }
+/*********************************************************************** + * RemoveDirectoryA (kernelbase.@) + */ +BOOL WINAPI DECLSPEC_HOTPATCH RemoveDirectoryA( LPCSTR path ) +{ + WCHAR *pathW; + + if (!(pathW = file_name_AtoW( path, FALSE ))) return FALSE; + return RemoveDirectoryW( pathW ); +} + + +/*********************************************************************** + * RemoveDirectoryW (kernelbase.@) + */ +BOOL WINAPI DECLSPEC_HOTPATCH RemoveDirectoryW( LPCWSTR path ) +{ + OBJECT_ATTRIBUTES attr; + UNICODE_STRING nt_name; + IO_STATUS_BLOCK io; + NTSTATUS status; + HANDLE handle; + + TRACE( "%s\n", debugstr_w(path) ); + + status = RtlDosPathNameToNtPathName_U_WithStatus( path, &nt_name, NULL, NULL ); + if (!set_ntstatus( status )) return FALSE; + + InitializeObjectAttributes( &attr, &nt_name, OBJ_CASE_INSENSITIVE, 0, NULL ); + status = NtOpenFile( &handle, DELETE | SYNCHRONIZE, &attr, &io, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT ); + RtlFreeUnicodeString( &nt_name ); + + if (!status) + { + FILE_DISPOSITION_INFORMATION info = { TRUE }; + status = NtSetInformationFile( handle, &io, &info, sizeof(info), FileDispositionInformation ); + NtClose( handle ); + } + return set_ntstatus( status ); +} + + /************************************************************************** * SetEndOfFile (kernelbase.@) */ diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index 8c184ff4f4..3f778685a7 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -1331,8 +1331,8 @@ @ stdcall ReleaseSemaphoreWhenCallbackReturns(ptr long long) ntdll.TpCallbackReleaseSemaphoreOnCompletion # @ stub ReleaseStateLock @ stdcall RemapPredefinedHandleInternal(long long) -@ stdcall RemoveDirectoryA(str) kernel32.RemoveDirectoryA -@ stdcall RemoveDirectoryW(wstr) kernel32.RemoveDirectoryW +@ stdcall RemoveDirectoryA(str) +@ stdcall RemoveDirectoryW(wstr) @ stdcall RemoveDllDirectory(ptr) # @ stub RemovePackageStatus # @ stub RemovePackageStatusForUser diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c index 9e65a1f6dd..6164b0c4bd 100644 --- a/dlls/ntdll/tests/file.c +++ b/dlls/ntdll/tests/file.c @@ -3082,16 +3082,17 @@ todo_wine fileDeleted = RemoveDirectoryA( buffer ); ok( fileDeleted, "Directory should have been deleted\n" ); fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND; -todo_wine ok( !fileDeleted, "Directory shouldn't have been deleted\n" ); res = nt_get_file_attrs( buffer, &fdi2 ); todo_wine ok( res == STATUS_DELETE_PENDING, "got %#x\n", res ); /* can't open the deleted directory */ handle2 = CreateFileA(buffer, DELETE, FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); +todo_wine ok( handle2 == INVALID_HANDLE_VALUE, "CreateFile should fail\n" ); todo_wine ok(GetLastError() == ERROR_ACCESS_DENIED, "got %u\n", GetLastError()); + if (handle2 != INVALID_HANDLE_VALUE) CloseHandle( handle2 ); CloseHandle( handle ); fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND; ok( fileDeleted, "Directory should have been deleted\n" );