Damjan Jovanovic : kernel32: CopyFile cannot overwrite a file with itself.
Alexandre Julliard
julliard at winehq.org
Fri Jun 11 09:58:32 CDT 2010
Module: wine
Branch: master
Commit: 3f1404bf29676d79dd76ffd31e2630bb9f2b0b60
URL: http://source.winehq.org/git/wine.git/?a=commit;h=3f1404bf29676d79dd76ffd31e2630bb9f2b0b60
Author: Damjan Jovanovic <damjan.jov at gmail.com>
Date: Thu Jun 10 22:14:13 2010 +0200
kernel32: CopyFile cannot overwrite a file with itself.
---
dlls/kernel32/path.c | 2 +-
dlls/kernel32/tests/file.c | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index c319cb5..2bfd062 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -911,7 +911,7 @@ BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists )
return FALSE;
}
- if ((h2 = CreateFileW( dest, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+ if ((h2 = CreateFileW( dest, GENERIC_WRITE, FILE_SHARE_READ, NULL,
fail_if_exists ? CREATE_NEW : CREATE_ALWAYS,
info.dwFileAttributes, h1 )) == INVALID_HANDLE_VALUE)
{
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c
index b6f066e..fcc7fc0 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 || broken(GetLastError() == ERROR_FILE_EXISTS) /* Win 9x */),
+ "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());
@@ -618,6 +622,14 @@ static void test_CopyFileA(void)
ret = CopyFileA(source, dest, FALSE);
ok(ret, "CopyFileA: error %d\n", GetLastError());
+ /* destination file is write-locked during copy */
+ hfile = CreateFileA(dest, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
+ ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %d\n", GetLastError());
+ retok = CopyFileA(source, dest, FALSE);
+ ok(!retok && GetLastError() == ERROR_SHARING_VIOLATION,
+ "copying to a write-locked file didn't fail (ret=%d, err=%d)\n", ret, GetLastError());
+ CloseHandle(hfile);
+
/* make sure that destination has correct size */
hfile = CreateFileA(dest, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
More information about the wine-cvs
mailing list