Comment 43 for bug 1210898

Revision history for this message
In , Peter F. Patel-Schneider (pfpschneider) wrote :

I see that 0.8.1 has your patch.

I think that better than waiting 1 second would be to try immediately and only then wait for a bit. I modified the code accordingly, ending up with

static gboolean
tvm_block_device_mount_volume (TvmContext *context, GVolume *volume)
{
  GMountOperation *mount_operation;

  /* check if we have a volume */
  if (volume != NULL)
    {
      /* check if we can mount the volume */
      if (g_volume_can_mount (volume))
        {
          /* try to mount the volume asynchronously */
          mount_operation = gtk_mount_operation_new (NULL);
          g_volume_mount (volume, G_MOUNT_MOUNT_NONE, mount_operation,
                          NULL, (GAsyncReadyCallback) tvm_block_device_mount_finish, context);
          g_object_unref (mount_operation);
        }
      else
        {
          g_set_error (context->error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("Unable to mount the device"));

          /* finish processing the device */
          tvm_device_handler_finished (context);
        }
    }
  else
    {
      g_set_error (context->error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                   _("Could not detect the volume corresponding to the device"));

      /* finish processing the device */
      tvm_device_handler_finished (context);
    }
    return FALSE;
}

static gboolean
tvm_block_device_mount_retry (TvmContext *context)
{
  GVolume *volume;

  volume =
    tvm_g_volume_monitor_get_volume_for_kind (context->monitor,
                                              G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE,
                                              g_udev_device_get_device_file (context->device));

  /* if no volume then call anyway to do not-found processing */
  tvm_block_device_mount_volume (context,volume);
  return FALSE;
}

static gboolean
tvm_block_device_mount (TvmContext *context)
{
  GVolume *volume;

  g_return_if_fail (context != NULL);

  /* determine the GVolume corresponding to the udev device */
  volume =
    tvm_g_volume_monitor_get_volume_for_kind (context->monitor,
                                              G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE,
                                              g_udev_device_get_device_file (context->device));
  if (volume != NULL)
    {
      tvm_block_device_mount_volume(context,volume);
    }
  else
    {
      /* clean up and try again in one second */
      g_object_unref (context->monitor);
      context->monitor = g_volume_monitor_get ();
      g_timeout_add_seconds(1, (GSourceFunc) tvm_block_device_mount_retry, context);
    }
  return FALSE;
}

What's the best way to get this put into thunar-volman?