From 7edfcd63ada3206b62f4fcee7b65d7a165a0cd9b Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Sun, 14 Oct 2018 10:44:37 +0300 Subject: [PATCH] kernel32: MoveFile(source, source) should succeed. Signed-off-by: Dmitry Timoshkov Signed-off-by: Alexandre Julliard --- dlls/kernel32/path.c | 15 ++++++++++----- dlls/kernel32/tests/file.c | 2 +- dlls/msvcp120/tests/msvcp120.c | 2 +- dlls/msvcp140/tests/msvcp140.c | 2 +- programs/cmd/tests/test_builtins.cmd.exp | 4 ++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c index 48a3e336ec7..33b2358f1ec 100644 --- a/dlls/kernel32/path.c +++ b/dlls/kernel32/path.c @@ -1281,7 +1281,7 @@ BOOL WINAPI MoveFileWithProgressW( LPCWSTR source, LPCWSTR dest, OBJECT_ATTRIBUTES attr; IO_STATUS_BLOCK io; NTSTATUS status; - HANDLE source_handle = 0, dest_handle; + HANDLE source_handle = 0, dest_handle = 0; ANSI_STRING source_unix, dest_unix; DWORD options; @@ -1341,18 +1341,22 @@ BOOL WINAPI MoveFileWithProgressW( LPCWSTR source, LPCWSTR dest, status = NtOpenFile( &dest_handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &attr, &io, 0, options ); if (status == STATUS_SUCCESS) /* destination exists */ { - NtClose( dest_handle ); if (!(flag & MOVEFILE_REPLACE_EXISTING)) { - SetLastError( ERROR_ALREADY_EXISTS ); - RtlFreeUnicodeString( &nt_name ); - goto error; + if (!is_same_file( source_handle, dest_handle )) + { + SetLastError( ERROR_ALREADY_EXISTS ); + RtlFreeUnicodeString( &nt_name ); + goto error; + } } else if (info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) /* cannot replace directory */ { SetLastError( ERROR_ACCESS_DENIED ); goto error; } + + NtClose( dest_handle ); } else if (status != STATUS_OBJECT_NAME_NOT_FOUND) { @@ -1412,6 +1416,7 @@ BOOL WINAPI MoveFileWithProgressW( LPCWSTR source, LPCWSTR dest, error: if (source_handle) NtClose( source_handle ); + if (dest_handle) NtClose( dest_handle ); RtlFreeAnsiString( &source_unix ); RtlFreeAnsiString( &dest_unix ); return FALSE; diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 433a2e55113..87e722b723b 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -1894,7 +1894,7 @@ static void test_MoveFileA(void) ok(ret != 0, "GetTempFileNameA error %d\n", GetLastError()); ret = MoveFileA(source, source); - todo_wine ok(ret, "MoveFileA: failed, error %d\n", GetLastError()); + ok(ret, "MoveFileA: failed, error %d\n", GetLastError()); ret = MoveFileA(source, dest); ok(!ret && GetLastError() == ERROR_ALREADY_EXISTS, diff --git a/dlls/msvcp120/tests/msvcp120.c b/dlls/msvcp120/tests/msvcp120.c index 2e63555f2e6..ac38aa61a0c 100644 --- a/dlls/msvcp120/tests/msvcp120.c +++ b/dlls/msvcp120/tests/msvcp120.c @@ -1529,7 +1529,7 @@ static void test_tr2_sys__Rename(void) CloseHandle(file); ret = p_tr2_sys__Rename("tr2_test_dir\\f1", "tr2_test_dir\\f1"); - todo_wine ok(ERROR_SUCCESS == ret, "test_tr2_sys__Rename(): expect: ERROR_SUCCESS, got %d\n", ret); + ok(ERROR_SUCCESS == ret, "test_tr2_sys__Rename(): expect: ERROR_SUCCESS, got %d\n", ret); for(i=0; i