mirror of
https://github.com/reactos/reactos.git
synced 2026-07-06 00:44:37 +08:00
[KERNEL32] BasepCopyFileExW: Check dwCopyFlags properly (#9133)
The function didn't check if `COPY_FILE_FAIL_IF_EXISTS` bit flag is set or not, always failing if _any_ flags were set and the destination file already existed. This behavior was probably implemented under assumption that `COPY_FILE_FAIL_IF_EXISTS` is the only valid flag, but it's not the case. There are other flags, so this was breaking applications when they intend to overwrite a file with e.g. `COPY_FILE_ALLOW_DECRYPTED_DESTINATION`. These functions were affected by the problem: - CopyFileEx - exposed by Total Commander not being able to overwrite file - PrivCopyFileEx - MoveFileWithProgress Also cover `ERROR_ALREADY_EXISTS` returned by CreateFileW to match Windows behavior, making the API tests pass. CORE-10271
This commit is contained in:
committed by
GitHub
parent
9127a5319b
commit
91146de1cd
@@ -254,11 +254,13 @@ BasepCopyFileExW(IN LPCWSTR lpExistingFileName,
|
||||
GENERIC_WRITE,
|
||||
FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
dwCopyFlags ? CREATE_NEW : CREATE_ALWAYS,
|
||||
(dwCopyFlags & COPY_FILE_FAIL_IF_EXISTS) ? CREATE_NEW : CREATE_ALWAYS,
|
||||
FileBasic.FileAttributes,
|
||||
NULL);
|
||||
if (INVALID_HANDLE_VALUE != FileHandleDest)
|
||||
{
|
||||
if (!(dwCopyFlags & COPY_FILE_FAIL_IF_EXISTS) && GetLastError() == ERROR_ALREADY_EXISTS)
|
||||
SetLastError(ERROR_SUCCESS);
|
||||
errCode = CopyLoop(FileHandleSource,
|
||||
FileHandleDest,
|
||||
FileStandard.EndOfFile,
|
||||
|
||||
Reference in New Issue
Block a user