[gvfs] udisks2: Set should_automount correctly when starting up



commit e30a67f3215d829e95ee7e358c67af7d67635fe8
Author: David Zeuthen <davidz redhat com>
Date:   Wed Apr 18 17:32:08 2012 -0400

    udisks2: Set should_automount correctly when starting up
    
    This bug caused volumes to not automount at session startup. While it
    can be argued that we should or shouldn't at least this is
    
        1. a change from earlier versions of GNOME; and
    
        2. rather disruptive for some non-GUI users
    
    Basically the problem is this: We need to take into account that on
    coldplug, the heuristic of just looking at whether the volume has
    appeared within the last five seconds won't work.
    
    This bug report that triggered this bug fix was this one
    
     https://bugzilla.redhat.com/show_bug.cgi?id=813069
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 monitor/udisks2/gvfsudisks2volume.c        |   17 +++++--
 monitor/udisks2/gvfsudisks2volume.h        |    3 +-
 monitor/udisks2/gvfsudisks2volumemonitor.c |   66 +++++++++++++++++----------
 3 files changed, 56 insertions(+), 30 deletions(-)
---
diff --git a/monitor/udisks2/gvfsudisks2volume.c b/monitor/udisks2/gvfsudisks2volume.c
index 8524267..89c2413 100644
--- a/monitor/udisks2/gvfsudisks2volume.c
+++ b/monitor/udisks2/gvfsudisks2volume.c
@@ -56,6 +56,9 @@ struct _GVfsUDisks2Volume
   GVfsUDisks2Mount         *mount;   /* owned by volume monitor */
   GVfsUDisks2Drive         *drive;   /* owned by volume monitor */
 
+  /* If TRUE, the volume was discovered at coldplug time */
+  gboolean coldplug;
+
   /* exactly one of these are set */
   UDisksBlock *block;
   GUnixMountPoint *mount_point;
@@ -326,14 +329,18 @@ update_volume (GVfsUDisks2Volume *volume)
            */
           if (udisks_block_get_hint_auto (volume->block))
             {
+              gboolean just_plugged_in = FALSE;
               /* Also, if a volume (partition) appear _much later_ than when media was inserted it
                * can only be because the media was repartitioned. We don't want to automount
                * such volumes. So only mark volumes appearing just after their drive.
+               *
+               * There's a catch here - if the volume was discovered at coldplug-time (typically
+               * when the user desktop session started), we can't use this heuristic
                */
               if (g_get_real_time () - udisks_drive_get_time_media_detected (udisks_drive) < 5 * G_USEC_PER_SEC)
-                {
-                  volume->should_automount = TRUE;
-                }
+                just_plugged_in = TRUE;
+              if (volume->coldplug || just_plugged_in)
+                volume->should_automount = TRUE;
             }
 
           g_object_unref (udisks_drive);
@@ -472,12 +479,14 @@ gvfs_udisks2_volume_new (GVfsUDisks2VolumeMonitor   *monitor,
                          UDisksBlock                *block,
                          GUnixMountPoint            *mount_point,
                          GVfsUDisks2Drive           *drive,
-                         GFile                      *activation_root)
+                         GFile                      *activation_root,
+                         gboolean                    coldplug)
 {
   GVfsUDisks2Volume *volume;
 
   volume = g_object_new (GVFS_TYPE_UDISKS2_VOLUME, NULL);
   volume->monitor = monitor;
+  volume->coldplug = coldplug;
 
   volume->sort_key = g_strdup_printf ("gvfs.time_detected_usec.%" G_GINT64_FORMAT, g_get_real_time ());
 
diff --git a/monitor/udisks2/gvfsudisks2volume.h b/monitor/udisks2/gvfsudisks2volume.h
index 1635ad2..586e5f6 100644
--- a/monitor/udisks2/gvfsudisks2volume.h
+++ b/monitor/udisks2/gvfsudisks2volume.h
@@ -41,7 +41,8 @@ GVfsUDisks2Volume *gvfs_udisks2_volume_new         (GVfsUDisks2VolumeMonitor   *
                                                     UDisksBlock                *block,
                                                     GUnixMountPoint            *mount_point,
                                                     GVfsUDisks2Drive           *drive,
-                                                    GFile                      *activation_root);
+                                                    GFile                      *activation_root,
+                                                    gboolean                    coldplug);
 void               gvfs_udisks2_volume_removed     (GVfsUDisks2Volume          *volume);
 
 UDisksBlock       *gvfs_udisks2_volume_get_block       (GVfsUDisks2Volume      *volume);
diff --git a/monitor/udisks2/gvfsudisks2volumemonitor.c b/monitor/udisks2/gvfsudisks2volumemonitor.c
index 3d5cbd5..1ea86b2 100644
--- a/monitor/udisks2/gvfsudisks2volumemonitor.c
+++ b/monitor/udisks2/gvfsudisks2volumemonitor.c
@@ -71,24 +71,30 @@ static void object_list_free (GList *objects);
 static UDisksClient *get_udisks_client_sync (GError **error);
 
 static void update_all               (GVfsUDisks2VolumeMonitor  *monitor,
-                                      gboolean                   emit_changes);
+                                      gboolean                   emit_changes,
+                                      gboolean                   coldplug);
 static void update_drives            (GVfsUDisks2VolumeMonitor  *monitor,
                                       GList                    **added_drives,
-                                      GList                    **removed_drives);
+                                      GList                    **removed_drives,
+                                      gboolean                   coldplug);
 static void update_volumes           (GVfsUDisks2VolumeMonitor  *monitor,
                                       GList                    **added_volumes,
-                                      GList                    **removed_volumes);
+                                      GList                    **removed_volumes,
+                                      gboolean                   coldplug);
 static void update_fstab_volumes     (GVfsUDisks2VolumeMonitor  *monitor,
                                       GList                    **added_volumes,
-                                      GList                    **removed_volumes);
+                                      GList                    **removed_volumes,
+                                      gboolean                   coldplug);
 static void update_mounts            (GVfsUDisks2VolumeMonitor  *monitor,
                                       GList                    **added_mounts,
-                                      GList                    **removed_mounts);
+                                      GList                    **removed_mounts,
+                                      gboolean                   coldplug);
 static void update_discs             (GVfsUDisks2VolumeMonitor  *monitor,
                                       GList                    **added_volumes,
                                       GList                    **removed_volumes,
                                       GList                    **added_mounts,
-                                      GList                    **removed_mounts);
+                                      GList                    **removed_mounts,
+                                      gboolean                   coldplug);
 
 
 static void on_client_changed (UDisksClient *client,
@@ -320,7 +326,7 @@ gvfs_udisks2_volume_monitor_init (GVfsUDisks2VolumeMonitor *monitor)
                     G_CALLBACK (mountpoints_changed),
                     monitor);
 
-  update_all (monitor, FALSE);
+  update_all (monitor, FALSE, TRUE);
 }
 
 static gboolean
@@ -388,7 +394,7 @@ gvfs_udisks2_volume_monitor_update (GVfsUDisks2VolumeMonitor *monitor)
 {
   g_return_if_fail (GVFS_IS_UDISKS2_VOLUME_MONITOR (monitor));
   udisks_client_settle (monitor->client);
-  update_all (monitor, TRUE);
+  update_all (monitor, TRUE, FALSE);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -496,7 +502,7 @@ on_client_changed (UDisksClient  *client,
                    gpointer       user_data)
 {
   GVfsUDisks2VolumeMonitor *monitor = GVFS_UDISKS2_VOLUME_MONITOR (user_data);
-  update_all (monitor, TRUE);
+  update_all (monitor, TRUE, FALSE);
 }
 
 static void
@@ -504,7 +510,7 @@ mountpoints_changed (GUnixMountMonitor *mount_monitor,
                      gpointer           user_data)
 {
   GVfsUDisks2VolumeMonitor *monitor = GVFS_UDISKS2_VOLUME_MONITOR (user_data);
-  update_all (monitor, TRUE);
+  update_all (monitor, TRUE, FALSE);
 }
 
 static void
@@ -512,14 +518,15 @@ mounts_changed (GUnixMountMonitor *mount_monitor,
                 gpointer           user_data)
 {
   GVfsUDisks2VolumeMonitor *monitor = GVFS_UDISKS2_VOLUME_MONITOR (user_data);
-  update_all (monitor, TRUE);
+  update_all (monitor, TRUE, FALSE);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
 update_all (GVfsUDisks2VolumeMonitor *monitor,
-            gboolean                  emit_changes)
+            gboolean                  emit_changes,
+            gboolean                  coldplug)
 {
   GList *added_drives, *removed_drives;
   GList *added_volumes, *removed_volumes;
@@ -532,13 +539,14 @@ update_all (GVfsUDisks2VolumeMonitor *monitor,
   added_mounts = NULL;
   removed_mounts = NULL;
 
-  update_drives (monitor, &added_drives, &removed_drives);
-  update_volumes (monitor, &added_volumes, &removed_volumes);
-  update_fstab_volumes (monitor, &added_volumes, &removed_volumes);
-  update_mounts (monitor, &added_mounts, &removed_mounts);
+  update_drives (monitor, &added_drives, &removed_drives, coldplug);
+  update_volumes (monitor, &added_volumes, &removed_volumes, coldplug);
+  update_fstab_volumes (monitor, &added_volumes, &removed_volumes, coldplug);
+  update_mounts (monitor, &added_mounts, &removed_mounts, coldplug);
   update_discs (monitor,
                 &added_volumes, &removed_volumes,
-                &added_mounts, &removed_mounts);
+                &added_mounts, &removed_mounts,
+                coldplug);
 
   if (emit_changes)
     {
@@ -1219,7 +1227,8 @@ find_mount_by_mount_path (GVfsUDisks2VolumeMonitor *monitor,
 static void
 update_drives (GVfsUDisks2VolumeMonitor  *monitor,
                GList                    **added_drives,
-               GList                    **removed_drives)
+               GList                    **removed_drives,
+               gboolean                   coldplug)
 {
   GList *cur_udisks_drives;
   GList *new_udisks_drives;
@@ -1303,7 +1312,8 @@ update_drives (GVfsUDisks2VolumeMonitor  *monitor,
 static void
 update_volumes (GVfsUDisks2VolumeMonitor  *monitor,
                 GList                    **added_volumes,
-                GList                    **removed_volumes)
+                GList                    **removed_volumes,
+                gboolean                   coldplug)
 {
   GList *cur_block_volumes;
   GList *new_block_volumes;
@@ -1369,7 +1379,8 @@ update_volumes (GVfsUDisks2VolumeMonitor  *monitor,
                                             block,
                                             NULL, /* mount_point */
                                             drive,
-                                            NULL); /* activation_root */
+                                            NULL, /* activation_root */
+                                            coldplug);
           if (volume != NULL)
             {
               monitor->volumes = g_list_prepend (monitor->volumes, volume);
@@ -1478,7 +1489,8 @@ mount_point_has_device (GVfsUDisks2VolumeMonitor  *monitor,
 static void
 update_fstab_volumes (GVfsUDisks2VolumeMonitor  *monitor,
                       GList                    **added_volumes,
-                      GList                    **removed_volumes)
+                      GList                    **removed_volumes,
+                      gboolean                   coldplug)
 {
   GList *cur_mount_points;
   GList *new_mount_points;
@@ -1543,7 +1555,8 @@ update_fstab_volumes (GVfsUDisks2VolumeMonitor  *monitor,
                                         NULL,        /* block */
                                         mount_point,
                                         NULL,        /* drive */
-                                        NULL);       /* activation_root */
+                                        NULL,        /* activation_root */
+                                        coldplug);
       if (volume != NULL)
         {
           GVfsUDisks2Mount *mount;
@@ -1573,7 +1586,8 @@ update_fstab_volumes (GVfsUDisks2VolumeMonitor  *monitor,
 static void
 update_mounts (GVfsUDisks2VolumeMonitor  *monitor,
                GList                    **added_mounts,
-               GList                    **removed_mounts)
+               GList                    **removed_mounts,
+               gboolean                   coldplug)
 {
   GList *cur_mounts;
   GList *new_mounts;
@@ -1689,7 +1703,8 @@ update_discs (GVfsUDisks2VolumeMonitor  *monitor,
               GList                    **added_volumes,
               GList                    **removed_volumes,
               GList                    **added_mounts,
-              GList                    **removed_mounts)
+              GList                    **removed_mounts,
+              gboolean                   coldplug)
 {
   GList *objects;
   GList *cur_disc_drives;
@@ -1790,7 +1805,8 @@ update_discs (GVfsUDisks2VolumeMonitor  *monitor,
                                                 block,
                                                 NULL, /* mount_point */
                                                 find_drive_for_udisks_drive (monitor, udisks_drive),
-                                                activation_root);
+                                                activation_root,
+                                                coldplug);
               if (volume != NULL)
                 {
                   monitor->disc_volumes = g_list_prepend (monitor->disc_volumes, volume);



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