[gnome-control-center/wip/carlosg/fix-device-removal-again] common: Fix again tracking of udev device removals



commit ac0031bf87834d9b9ca32f1b65cf87a8acd97d94
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Dec 5 16:20:02 2019 +0100

    common: Fix again tracking of udev device removals
    
    This got fixed in commit 008b1f68c8, and broken again the very same
    way in commit 3600cb5a40. Go me.

 panels/common/gsd-device-manager.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/panels/common/gsd-device-manager.c b/panels/common/gsd-device-manager.c
index 07f0d4fd8..1ce2fd743 100644
--- a/panels/common/gsd-device-manager.c
+++ b/panels/common/gsd-device-manager.c
@@ -422,6 +422,7 @@ add_device (GsdDeviceManager *manager,
         GsdDeviceManagerPrivate *priv = gsd_device_manager_get_instance_private (manager);
        GUdevDevice *parent;
        GsdDevice *device;
+       const gchar *syspath;
 
        parent = g_udev_device_get_parent (udev_device);
 
@@ -429,7 +430,8 @@ add_device (GsdDeviceManager *manager,
                return;
 
        device = create_device (udev_device);
-       g_hash_table_insert (priv->devices, g_object_ref (udev_device), device);
+       syspath = g_udev_device_get_sysfs_path (udev_device);
+       g_hash_table_insert (priv->devices, g_strdup (syspath), device);
        g_signal_emit_by_name (manager, "device-added", device);
 }
 
@@ -437,15 +439,17 @@ static void
 remove_device (GsdDeviceManager *manager,
               GUdevDevice      *udev_device)
 {
-        GsdDeviceManagerPrivate *priv = gsd_device_manager_get_instance_private (manager);
+       GsdDeviceManagerPrivate *priv = gsd_device_manager_get_instance_private (manager);
        GsdDevice *device;
+       const gchar *syspath;
 
-       device = g_hash_table_lookup (priv->devices, udev_device);
+       syspath = g_udev_device_get_sysfs_path (udev_device);
+       device = g_hash_table_lookup (priv->devices, syspath);
 
        if (!device)
                return;
 
-       g_hash_table_steal (priv->devices, udev_device);
+       g_hash_table_steal (priv->devices, syspath);
        g_signal_emit_by_name (manager, "device-removed", device);
 
        g_object_unref (device);
@@ -476,9 +480,9 @@ gsd_device_manager_init (GsdDeviceManager *manager)
        g_autoptr(GList) devices = NULL;
        GList *l;
 
-       priv->devices = g_hash_table_new_full (NULL, NULL,
-                                               (GDestroyNotify) g_object_unref,
-                                               (GDestroyNotify) g_object_unref);
+       priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                              (GDestroyNotify) g_free,
+                                              (GDestroyNotify) g_object_unref);
 
        priv->udev_client = g_udev_client_new (subsystems);
        g_signal_connect (priv->udev_client, "uevent",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]