shell32: Allow copy operation to overwrite an existing write protected file + tests.
This commit is contained in:
parent
fc7f1c7e5a
commit
240afab362
|
@ -624,9 +624,15 @@ static DWORD SHNotifyMoveFileW(LPCWSTR src, LPCWSTR dest)
|
|||
static DWORD SHNotifyCopyFileW(LPCWSTR src, LPCWSTR dest, BOOL bFailIfExists)
|
||||
{
|
||||
BOOL ret;
|
||||
DWORD attribs;
|
||||
|
||||
TRACE("(%s %s %s)\n", debugstr_w(src), debugstr_w(dest), bFailIfExists ? "failIfExists" : "");
|
||||
|
||||
/* Destination file may already exist with read only attribute */
|
||||
attribs = GetFileAttributesW(dest);
|
||||
if (IsAttrib(attribs, FILE_ATTRIBUTE_READONLY))
|
||||
SetFileAttributesW(dest, attribs & ~FILE_ATTRIBUTE_READONLY);
|
||||
|
||||
ret = CopyFileW(src, dest, bFailIfExists);
|
||||
if (ret)
|
||||
{
|
||||
|
@ -1132,7 +1138,7 @@ static BOOL copy_file_to_file(FILE_OPERATION *op, const WCHAR *szFrom, const WCH
|
|||
if (!SHELL_ConfirmDialogW(op->req->hwnd, ASK_OVERWRITE_FILE, PathFindFileNameW(szTo), op))
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return SHNotifyCopyFileW(szFrom, szTo, FALSE) == 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -965,6 +965,26 @@ static void test_copy(void)
|
|||
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
||||
ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
|
||||
|
||||
/* try to overwrite an existing write protected file */
|
||||
clean_after_shfo_tests();
|
||||
init_shfo_tests();
|
||||
tmp_flags = shfo.fFlags;
|
||||
shfo.pFrom = "test1.txt\0";
|
||||
shfo.pTo = "test2.txt\0";
|
||||
/* suppress the error-dialog in win9x here */
|
||||
shfo.fFlags = FOF_NOERRORUI | FOF_NOCONFIRMATION | FOF_SILENT;
|
||||
ok(SetFileAttributesA(shfo.pTo, FILE_ATTRIBUTE_READONLY),
|
||||
"Failure to set file attributes (error %x)\n", GetLastError());
|
||||
retval = CopyFileA(shfo.pFrom, shfo.pTo, FALSE);
|
||||
ok(!retval && GetLastError() == ERROR_ACCESS_DENIED, "CopyFileA should have fail with ERROR_ACCESS_DENIED\n");
|
||||
retval = SHFileOperationA(&shfo);
|
||||
/* Does not work on Win95, Win95B, NT4WS and NT4SRV */
|
||||
ok(!retval || broken(retval == DE_OPCANCELLED), "SHFileOperationA failed to copy (error %x)\n", retval);
|
||||
/* Set back normal attributes to make the file deletion succeed */
|
||||
ok(SetFileAttributesA(shfo.pTo, FILE_ATTRIBUTE_NORMAL),
|
||||
"Failure to set file attributes (error %x)\n", GetLastError());
|
||||
shfo.fFlags = tmp_flags;
|
||||
|
||||
/* try to copy files to a file */
|
||||
clean_after_shfo_tests();
|
||||
init_shfo_tests();
|
||||
|
|
Loading…
Reference in New Issue