[0.4.9][SHELL32] Copy without FILE_ATTRIBUTE_READONLY from a CDROM CORE-18089 (#4386)

That problem in the shell was unhidden when we switched from our own to the MS-PL CDFS-driver
in 0.4.8-dev-164-g ec6b3ecbe4
because our own old CDFS driver erroneously never reported any CD file being read-only.

Fix picked from 0.4.15-dev-4348-g 513d0a6d2d

While backporting the fix, I decided to port back also some EOL-whitespace-stripping in that file.
This commit is contained in:
Joachim Henze 2022-09-22 16:19:22 +02:00
parent 2986b27f7d
commit 275c4442bb

View file

@ -711,6 +711,21 @@ static DWORD SHNotifyMoveFileW(FILE_OPERATION *op, LPCWSTR src, LPCWSTR dest, BO
return GetLastError();
}
static BOOL SHIsCdRom(LPCWSTR path)
{
WCHAR tmp[] = { L"A:\\" };
if (!path || !path[0])
return FALSE;
if (path[1] != UNICODE_NULL && path[1] != ':')
return FALSE;
tmp[0] = path[0];
return GetDriveTypeW(tmp) == DRIVE_CDROM;
}
/************************************************************************
* SHNotifyCopyFile [internal]
*
@ -751,6 +766,14 @@ static DWORD SHNotifyCopyFileW(FILE_OPERATION *op, LPCWSTR src, LPCWSTR dest, BO
ret = CopyFileExW(src, dest, SHCopyProgressRoutine, op, &op->bCancelled, bFailIfExists);
if (ret)
{
// We are copying from a CD-ROM volume, which is readonly
if (SHIsCdRom(src))
{
attribs = GetFileAttributesW(dest);
attribs &= ~FILE_ATTRIBUTE_READONLY;
SetFileAttributesW(dest, attribs);
}
SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, dest, NULL);
return ERROR_SUCCESS;
}