mirror of
https://github.com/reactos/reactos.git
synced 2025-01-03 21:09:19 +00:00
Dmitry Philippov: In MoveFileWithProgressW()
- Change alloca() to RtlAllocateHeap() and add missing freeing of the allocated space - Fix incorrect FileNameLength param in call to NtSetInformationFile() - Add support for MOVEFILE_REPLACE_EXISTING flag svn path=/trunk/; revision=23570
This commit is contained in:
parent
81ff664e0c
commit
48ed6cd4d0
1 changed files with 14 additions and 8 deletions
|
@ -274,7 +274,15 @@ MoveFileWithProgressW (
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
FileRename = alloca(sizeof(FILE_RENAME_INFORMATION) + DstPathU.Length);
|
||||
FileRename = RtlAllocateHeap(
|
||||
RtlGetProcessHeap(),
|
||||
HEAP_ZERO_MEMORY,
|
||||
sizeof(FILE_RENAME_INFORMATION) + DstPathU.Length);
|
||||
if( !FileRename ) {
|
||||
CloseHandle(hFile);
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
return FALSE;
|
||||
}
|
||||
if( dwFlags & MOVEFILE_REPLACE_EXISTING ) {
|
||||
FileRename->ReplaceIfExists = TRUE;
|
||||
}
|
||||
|
@ -287,17 +295,15 @@ MoveFileWithProgressW (
|
|||
RtlFreeHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
DstPathU.Buffer);
|
||||
/*
|
||||
* FIXME:
|
||||
* Is the length the count of characters or the length of the buffer?
|
||||
*/
|
||||
FileRename->FileNameLength = DstPathU.Length / sizeof(WCHAR);
|
||||
|
||||
FileRename->FileNameLength = DstPathU.Length;
|
||||
errCode = NtSetInformationFile (hFile,
|
||||
&IoStatusBlock,
|
||||
FileRename,
|
||||
sizeof(FILE_RENAME_INFORMATION) + DstPathU.Length,
|
||||
FileRenameInformation);
|
||||
CloseHandle(hFile);
|
||||
RtlFreeHeap(RtlGetProcessHeap(), 0, FileRename);
|
||||
|
||||
if (GetFileAttributesW(lpExistingFileName) & FILE_ATTRIBUTE_DIRECTORY)
|
||||
{
|
||||
|
@ -325,12 +331,12 @@ MoveFileWithProgressW (
|
|||
lpProgressRoutine,
|
||||
lpData,
|
||||
NULL,
|
||||
FileRename->ReplaceIfExists ? 0 : COPY_FILE_FAIL_IF_EXISTS);
|
||||
(dwFlags & MOVEFILE_REPLACE_EXISTING) ? 0 : COPY_FILE_FAIL_IF_EXISTS);
|
||||
if (Result)
|
||||
{
|
||||
/* Cleanup the source file */
|
||||
Result = DeleteFileW (lpExistingFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue