[gnome-disk-utility/kailueke/wait-for-udisks-unmount: 2/2] Wait until UDisks updates the unmounted filesystem



commit 7749ff947ba95f3b413a47ba257be71125224728
Author: Kai Lüke <kailueke riseup net>
Date:   Fri Mar 6 00:23:44 2020 +0100

    Wait until UDisks updates the unmounted filesystem
    
    Before the Filesystem.Unmount method returns it does
    not make sure that the mount point is removed from
    the list stored as filesystem property.
    I solved this once with a waiter in
    https://github.com/storaged-project/udisks/pull/574
    but since a couple of months the error is back.
    Work around this in GNOME Disks by waiting
    until the property has changed (i.e., the list has
    a different size). Just in case something else gets
    messed up, a timeout of 5 seconds is added, too.
    
    In future UDisks releases this will be fixed by
    https://github.com/storaged-project/udisks/pull/728

 src/libgdu/gduutils.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/src/libgdu/gduutils.c b/src/libgdu/gduutils.c
index bff70304..d46254ad 100644
--- a/src/libgdu/gduutils.c
+++ b/src/libgdu/gduutils.c
@@ -1351,6 +1351,7 @@ typedef struct
   GList *object_iter;
   GTask *task;
   GCancellable *cancellable; /* borrowed ref */
+  guint last_mount_point_list_size; /* only for unuse_unmount_cb to check against a race in UDisks */
 } UnuseData;
 
 static void
@@ -1399,6 +1400,18 @@ unuse_unmount_cb (UDisksFilesystem *filesystem,
     }
   else
     {
+      gint64 end_usec;
+      const gchar *const *mount_points;
+
+      end_usec = g_get_monotonic_time () + (G_USEC_PER_SEC * 5);
+
+      while (mount_points = udisks_filesystem_get_mount_points (filesystem),
+             (mount_points ? g_strv_length ((gchar **) mount_points) : 0) == 
data->last_mount_point_list_size &&
+             g_get_monotonic_time () < end_usec)
+      {
+        udisks_client_settle (data->client);
+      }
+
       unuse_data_iterate (data);
     }
 }
@@ -1492,6 +1505,10 @@ unuse_data_iterate (UnuseData *data)
 
   if (filesystem_to_unmount != NULL)
     {
+      const gchar *const *mount_points;
+
+      mount_points = udisks_filesystem_get_mount_points (filesystem_to_unmount);
+      data->last_mount_point_list_size = mount_points ? g_strv_length ((gchar **) mount_points) : 0;
       udisks_filesystem_call_unmount (filesystem_to_unmount,
                                       g_variant_new ("a{sv}", NULL), /* options */
                                       data->cancellable, /* cancellable */


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