kernel32: CopyFile cannot overwrite a file with itself
Damjan Jovanovic
damjan.jov at gmail.com
Mon Jun 7 06:29:48 CDT 2010
Changelog:
* kernel32: CopyFile cannot overwrite a file with itself
Fixes #21156.
Damjan Jovanovic
-------------- next part --------------
diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index c319cb5..9c88b6c 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -895,7 +895,7 @@ BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists )
TRACE("%s -> %s\n", debugstr_w(source), debugstr_w(dest));
- if ((h1 = CreateFileW(source, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ if ((h1 = CreateFileW(source, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
{
WARN("Unable to open source %s\n", debugstr_w(source));
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c
index b6f066e..5c78857 100644
--- a/dlls/kernel32/tests/file.c
+++ b/dlls/kernel32/tests/file.c
@@ -598,6 +598,10 @@ static void test_CopyFileA(void)
ok( retok && ret == sizeof(prefix),
"WriteFile error %d\n", GetLastError());
ok(GetFileSize(hfile, NULL) == sizeof(prefix), "source file has wrong size\n");
+ /* copying a file to itself must fail */
+ retok = CopyFileA(source, source, FALSE);
+ ok( !retok && GetLastError() == ERROR_SHARING_VIOLATION,
+ "copying a file to itself didn't fail (ret=%d, err=%d)\n", retok, GetLastError());
/* get the file time and change it to prove the difference */
ret = GetFileTime(hfile, NULL, NULL, &ft1);
ok( ret, "GetFileTime error %d\n", GetLastError());
More information about the wine-patches
mailing list