native_path = g_udev_device_get_sysfs_path (d);
device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
if (device != NULL) {
+ gboolean keep_device;
+
g_print ("**** CHANGING %s\n", native_path);
/* The device file (udev rules) and/or sysfs path ('move' uevent) may actually change so
g_warn_if_fail (g_hash_table_remove (daemon->priv->map_device_file_to_device,
device->priv->device_file));
- if (!devkit_disks_device_changed (device, d, synthesized)) {
+ keep_device = devkit_disks_device_changed (device, d, synthesized);
+
+ g_assert (devkit_disks_device_local_get_device_file (device) != NULL);
+ g_assert (devkit_disks_device_local_get_native_path (device) != NULL);
+ g_assert (g_strcmp0 (native_path, devkit_disks_device_local_get_native_path (device)) == 0);
+
+ /* now add the things back to the global hashtables - it's important that we
+ * do this *before* calling device_remove() - otherwise it will never remove
+ * the device
+ */
+ g_hash_table_insert (daemon->priv->map_device_file_to_device,
+ g_strdup (devkit_disks_device_local_get_device_file (device)),
+ g_object_ref (device));
+ g_hash_table_insert (daemon->priv->map_native_path_to_device,
+ g_strdup (devkit_disks_device_local_get_native_path (device)),
+ g_object_ref (device));
+
+ if (!keep_device) {
g_print ("**** CHANGE TRIGGERED REMOVE %s\n", native_path);
device_remove (daemon, d);
} else {
g_print ("**** CHANGED %s\n", native_path);
- g_assert (devkit_disks_device_local_get_device_file (device) != NULL);
- g_assert (devkit_disks_device_local_get_native_path (device) != NULL);
- g_assert (g_strcmp0 (native_path, devkit_disks_device_local_get_native_path (device)) == 0);
-
- /* now add the things back to the global hashtables */
- g_hash_table_insert (daemon->priv->map_device_file_to_device,
- g_strdup (devkit_disks_device_local_get_device_file (device)),
- g_object_ref (device));
- g_hash_table_insert (daemon->priv->map_native_path_to_device,
- g_strdup (devkit_disks_device_local_get_native_path (device)),
- g_object_ref (device));
-
devkit_disks_daemon_local_update_poller (daemon);
devkit_disks_daemon_local_update_spindown (daemon);
}
g_warn_if_fail (g_hash_table_remove (daemon->priv->map_dev_t_to_device,
GINT_TO_POINTER (device->priv->dev)));
- devkit_disks_device_removed (device);
-
g_print ("**** EMITTING REMOVED for %s\n", device->priv->native_path);
g_signal_emit (daemon, signals[DEVICE_REMOVED_SIGNAL], 0,
devkit_disks_device_local_get_object_path (device));
+ devkit_disks_device_removed (device);
+
g_object_unref (device);
devkit_disks_daemon_local_update_poller (daemon);
device->priv->object_path = compute_object_path (device->priv->native_path);
+ /* safety first */
if (dbus_g_connection_lookup_g_object (device->priv->system_bus_connection,
device->priv->object_path) != NULL) {
- /* TODO: see devkit_disks_device_removed() for where we want to unregister the object but
- * we're missing the API. So do it manually here if we are forced to do so...
- */
-
- g_print ("**** HACK: Wanting to register object at path `%s' but there is already an "
- "object there. Using a hack to move it out of the way.\n",
+ g_error ("**** HACK: Wanting to register object at path `%s' but there is already an "
+ "object there. This is an internal error in the daemon. Aborting.\n",
device->priv->object_path);
-
- dbus_connection_unregister_object_path (dbus_g_connection_get_connection (device->priv->system_bus_connection),
- device->priv->object_path);
}
dbus_g_connection_register_g_object (device->priv->system_bus_connection,
{
UpdateInfoInIdleData *data = user_data;
- update_info (data->device);
+ /* this indirectly calls update_info and also removes the device
+ * if it wants to be removed (e.g. if update_info() returns FALSE)
+ */
+ devkit_disks_daemon_local_synthesize_changed (data->device->priv->daemon, data->device);
return FALSE; /* remove source */
}
device->priv->removed = TRUE;
- /* TODO: this is in a yet to be released version of dbus-glib, use it when available
-
dbus_g_connection_unregister_g_object (device->priv->system_bus_connection,
G_OBJECT (device));
- */
+ g_assert (dbus_g_connection_lookup_g_object (device->priv->system_bus_connection,
+ device->priv->object_path) == NULL);
/* device is now removed; update all slaves and holders */
for (n = 0; n < device->priv->slaves_objpath->len; n++) {