From f4546a18e871537be698916178b40091a4a0b377 Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer@who-t.net>
Date: Fri, 12 Nov 2021 11:19:54 +1000
Subject: [PATCH 3/3] m-reserve-device: replace the hash table key on new
 insert

We're using the WpReserveDevice's name as key in the hash table, so we
must update the key as well when we replace an item in the hashtable -
the old device (and its name) will be released.

The side-effect of this is that the *third* device with an identical
name will no longer replace the previous device. This results in the
following sequence:

- dev1 added: name Audio0
  - dev1 requests name owner Audio0
- dev2 added: name Audio0
  - replace dev1 in the hashtable
     - dev1 emits "release" signal
     - dev1 unowns the Audio0 name
  - dev2 requests name owner Audio0
- dev3 added: name Audio0
  - adds to the hashtable because the existing key is now undefined
  - dev3 requests name owner Audio0
     - error, you cannot request ownership for the same name twice

Fixes #93
---
 modules/module-reserve-device/plugin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/module-reserve-device/plugin.c b/modules/module-reserve-device/plugin.c
index d8e4e09..68df6ee 100644
--- a/modules/module-reserve-device/plugin.c
+++ b/modules/module-reserve-device/plugin.c
@@ -221,7 +221,7 @@ wp_reserve_device_plugin_create_reservation (WpReserveDevicePlugin *self,
       NULL);
 
   /* use rd->name to avoid copying @em name again */
-  g_hash_table_insert (self->reserve_devices, rd->name, rd);
+  g_hash_table_replace (self->reserve_devices, rd->name, rd);
 
   return g_object_ref (rd);
 }
-- 
2.34.0

