Use a larger buffer in CopyFileW now that the file handle may not

always be cached.
This commit is contained in:
Alexandre Julliard 2005-09-26 13:26:40 +00:00
parent fbbb32d6d1
commit 81d64af17e
1 changed files with 10 additions and 6 deletions

View File

@ -849,18 +849,23 @@ DWORD WINAPI SearchPathA( LPCSTR path, LPCSTR name, LPCSTR ext,
*/ */
BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists ) BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists )
{ {
static const int buffer_size = 65536;
HANDLE h1, h2; HANDLE h1, h2;
BY_HANDLE_FILE_INFORMATION info; BY_HANDLE_FILE_INFORMATION info;
FILETIME filetime;
DWORD count; DWORD count;
BOOL ret = FALSE; BOOL ret = FALSE;
char buffer[2048]; char *buffer;
if (!source || !dest) if (!source || !dest)
{ {
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
} }
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
TRACE("%s -> %s\n", debugstr_w(source), debugstr_w(dest)); TRACE("%s -> %s\n", debugstr_w(source), debugstr_w(dest));
@ -887,7 +892,7 @@ BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists )
return FALSE; return FALSE;
} }
while (ReadFile( h1, buffer, sizeof(buffer), &count, NULL ) && count) while (ReadFile( h1, buffer, buffer_size, &count, NULL ) && count)
{ {
char *p = buffer; char *p = buffer;
while (count != 0) while (count != 0)
@ -901,9 +906,8 @@ BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists )
ret = TRUE; ret = TRUE;
done: done:
/* Maintain the timestamp of source file to destination file */ /* Maintain the timestamp of source file to destination file */
GetFileTime(h1, NULL, NULL, &filetime); SetFileTime(h2, NULL, NULL, &info.ftLastWriteTime);
SetFileTime(h2, NULL, NULL, &filetime); HeapFree( GetProcessHeap(), 0, buffer );
CloseHandle( h1 ); CloseHandle( h1 );
CloseHandle( h2 ); CloseHandle( h2 );
return ret; return ret;