Skip to content

Commit 91146de

Browse files
authored
[KERNEL32] BasepCopyFileExW: Check dwCopyFlags properly (reactos#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
1 parent 9127a53 commit 91146de

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

  • dll/win32/kernel32/client/file

‎dll/win32/kernel32/client/file/copy.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,13 @@ BasepCopyFileExW(IN LPCWSTR lpExistingFileName,
254254
GENERIC_WRITE,
255255
FILE_SHARE_WRITE,
256256
NULL,
257-
dwCopyFlags ? CREATE_NEW : CREATE_ALWAYS,
257+
(dwCopyFlags & COPY_FILE_FAIL_IF_EXISTS) ? CREATE_NEW : CREATE_ALWAYS,
258258
FileBasic.FileAttributes,
259259
NULL);
260260
if (INVALID_HANDLE_VALUE != FileHandleDest)
261261
{
262+
if (!(dwCopyFlags & COPY_FILE_FAIL_IF_EXISTS) && GetLastError() == ERROR_ALREADY_EXISTS)
263+
SetLastError(ERROR_SUCCESS);
262264
errCode = CopyLoop(FileHandleSource,
263265
FileHandleDest,
264266
FileStandard.EndOfFile,

0 commit comments

Comments
 (0)