Check drive to hotplug for already being redirected

some hotplug implementations report the same drive multiple times.
to avoid redirecting the same drive multiple times check if it is
already in the list before adding.

(cherry picked from commit 9e8d3fbbf5)
This commit is contained in:
akallabeth 2021-01-15 10:41:12 +01:00 committed by akallabeth
parent 605e89a38d
commit 2ce5f6f17c

View File

@ -736,6 +736,37 @@ static UINT handle_platform_mounts(hotplug_dev* dev_array, size_t* size)
return ERROR_CALL_NOT_IMPLEMENTED;
}
static BOOL device_already_plugged(rdpdrPlugin* rdpdr, const hotplug_dev* device)
{
BOOL rc = FALSE;
int count, x;
ULONG_PTR* keys = NULL;
if (!rdpdr || !device)
return TRUE;
if (!device->to_add)
return TRUE;
ListDictionary_Lock(rdpdr->devman->devices);
count = ListDictionary_GetKeys(rdpdr->devman->devices, &keys);
for (x = 0; x < count; x++)
{
DEVICE_DRIVE_EXT* device_ext =
(DEVICE_DRIVE_EXT*)ListDictionary_GetItemValue(rdpdr->devman->devices, (void*)keys[x]);
if (!device_ext || (device_ext->device.type != RDPDR_DTYP_FILESYSTEM) || !device_ext->path)
continue;
if (strcmp(device_ext->path, device->path) == 0)
{
rc = TRUE;
break;
}
}
free(keys);
ListDictionary_Unlock(rdpdr->devman->devices);
return rc;
}
/**
* Function description
*
@ -806,7 +837,7 @@ static UINT handle_hotplug(rdpdrPlugin* rdpdr)
/* add new devices */
for (i = 0; i < size; i++)
{
if (dev_array[i].to_add)
if (!device_already_plugged(rdpdr, &dev_array[i]))
{
RDPDR_DRIVE drive = { 0 };
char* name;