[gvfs] udisks2: Do not show notification if unmount failed



commit 1758ee7778cf60533494eb455e32b6d91f4b87fa
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Oct 6 16:14:46 2015 +0200

    udisks2: Do not show notification if unmount failed
    
    "You can now unplug..." notification is shown regardless of errors
    currently. Error dialog is shown together with this notification.
    Device might be still mounted and it might not be safe to unmount it.
    Therefore show this notification only if there are no errors.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=746769

 monitor/udisks2/gvfsudisks2drive.c |    6 +++---
 monitor/udisks2/gvfsudisks2mount.c |   18 +++++++++++++++---
 monitor/udisks2/gvfsudisks2utils.c |    5 +++--
 monitor/udisks2/gvfsudisks2utils.h |    3 ++-
 4 files changed, 23 insertions(+), 9 deletions(-)
---
diff --git a/monitor/udisks2/gvfsudisks2drive.c b/monitor/udisks2/gvfsudisks2drive.c
index 6ea6b82..5cc0006 100644
--- a/monitor/udisks2/gvfsudisks2drive.c
+++ b/monitor/udisks2/gvfsudisks2drive.c
@@ -610,7 +610,7 @@ unmount_mounts_cb (GObject      *source_object,
         }
 
       if (data->mount_operation != NULL)
-        gvfs_udisks2_unmount_notify_stop (data->mount_operation);
+        gvfs_udisks2_unmount_notify_stop (data->mount_operation, error != NULL);
 
       /* unmount failed; need to fail the whole eject operation */
       simple = g_simple_async_result_new_from_error (G_OBJECT (data->drive),
@@ -707,7 +707,7 @@ eject_cb (GObject      *source_object,
       if (error != NULL)
         g_signal_emit_by_name (data->mount_operation, "aborted");
 
-      gvfs_udisks2_unmount_notify_stop (data->mount_operation);
+      gvfs_udisks2_unmount_notify_stop (data->mount_operation, error != NULL);
     }
 
   g_simple_async_result_complete (data->simple);
@@ -849,7 +849,7 @@ power_off_cb (GObject      *source_object,
       if (error != NULL)
         g_signal_emit_by_name (data->mount_operation, "aborted");
 
-      gvfs_udisks2_unmount_notify_stop (data->mount_operation);
+      gvfs_udisks2_unmount_notify_stop (data->mount_operation, error != NULL);
     }
 
   g_simple_async_result_complete (data->simple);
diff --git a/monitor/udisks2/gvfsudisks2mount.c b/monitor/udisks2/gvfsudisks2mount.c
index 8607490..dced43a 100644
--- a/monitor/udisks2/gvfsudisks2mount.c
+++ b/monitor/udisks2/gvfsudisks2mount.c
@@ -529,6 +529,7 @@ typedef struct
   GSimpleAsyncResult *simple;
   gboolean in_progress;
   gboolean completed;
+  gboolean failed;
 
   GVfsUDisks2Mount *mount;
 
@@ -601,7 +602,7 @@ unmount_data_complete (UnmountData *data,
 {
   if (data->mount_operation &&
       !unmount_operation_is_eject (data->mount_operation))
-    gvfs_udisks2_unmount_notify_stop (data->mount_operation);
+    gvfs_udisks2_unmount_notify_stop (data->mount_operation, data->failed);
 
   if (complete_idle)
     g_simple_async_result_complete_in_idle (data->simple);
@@ -651,6 +652,7 @@ mount_op_reply_handle (UnmountData *data)
                                        G_IO_ERROR_FAILED_HANDLED,
                                        "GMountOperation aborted (user should never see this "
                                        "error since it is G_IO_ERROR_FAILED_HANDLED)");
+      data->failed = TRUE;
       unmount_data_complete (data, TRUE);
     }
   else if (data->reply_result == G_MOUNT_OPERATION_HANDLED)
@@ -667,6 +669,7 @@ mount_op_reply_handle (UnmountData *data)
                                        G_IO_ERROR,
                                        G_IO_ERROR_BUSY,
                                        _("One or more programs are preventing the unmount operation."));
+      data->failed = TRUE;
       unmount_data_complete (data, TRUE);
     }
 }
@@ -843,7 +846,11 @@ lock_cb (GObject       *source_object,
   if (!udisks_encrypted_call_lock_finish (encrypted,
                                           res,
                                           &error))
-    g_simple_async_result_take_error (data->simple, error);
+    {
+      g_simple_async_result_take_error (data->simple, error);
+      data->failed = TRUE;
+    }
+
   unmount_data_complete (data, FALSE);
 }
 
@@ -870,6 +877,7 @@ unmount_cb (GObject       *source_object,
           goto out;
         }
       g_simple_async_result_take_error (data->simple, error);
+      data->failed = TRUE;
     }
   else
     {
@@ -911,6 +919,7 @@ umount_command_cb (GObject       *source_object,
                                         &error))
     {
       g_simple_async_result_take_error (data->simple, error);
+      data->failed = TRUE;
       unmount_data_complete (data, FALSE);
       goto out;
     }
@@ -934,6 +943,7 @@ umount_command_cb (GObject       *source_object,
                                    G_IO_ERROR,
                                    G_IO_ERROR_FAILED,
                                    "%s", standard_error);
+  data->failed = TRUE;
   unmount_data_complete (data, FALSE);
 
  out:
@@ -1039,7 +1049,7 @@ gvfs_udisks2_mount_unmount_with_operation (GMount              *_mount,
                                            G_IO_ERROR,
                                            G_IO_ERROR_FAILED,
                                            "No object for D-Bus interface");
-
+          data->failed = TRUE;
           unmount_data_complete (data, FALSE);
           goto out;
         }
@@ -1055,6 +1065,7 @@ gvfs_udisks2_mount_unmount_with_operation (GMount              *_mount,
                                                G_IO_ERROR,
                                                G_IO_ERROR_FAILED,
                                                "No filesystem or encrypted interface on D-Bus object");
+              data->failed = TRUE;
               unmount_data_complete (data, FALSE);
               goto out;
             }
@@ -1071,6 +1082,7 @@ gvfs_udisks2_mount_unmount_with_operation (GMount              *_mount,
                                                    G_IO_ERROR,
                                                    G_IO_ERROR_FAILED,
                                                    "No filesystem interface on D-Bus object for cleartext 
device");
+                  data->failed = TRUE;
                   unmount_data_complete (data, FALSE);
                   goto out;
                 }
diff --git a/monitor/udisks2/gvfsudisks2utils.c b/monitor/udisks2/gvfsudisks2utils.c
index 416d5e5..9519a99 100644
--- a/monitor/udisks2/gvfsudisks2utils.c
+++ b/monitor/udisks2/gvfsudisks2utils.c
@@ -801,7 +801,8 @@ gvfs_udisks2_unmount_notify_start (GMountOperation *op,
 }
 
 void
-gvfs_udisks2_unmount_notify_stop (GMountOperation *op)
+gvfs_udisks2_unmount_notify_stop (GMountOperation *op,
+                                  gboolean         unmount_failed)
 {
   gchar *message, *name;
   const gchar *format;
@@ -812,7 +813,7 @@ gvfs_udisks2_unmount_notify_stop (GMountOperation *op)
 
   unmount_notify_stop_timer (data);
 
-  if (data->op_aborted)
+  if (data->op_aborted || unmount_failed)
     return;
 
   name = unmount_notify_get_name (data);
diff --git a/monitor/udisks2/gvfsudisks2utils.h b/monitor/udisks2/gvfsudisks2utils.h
index ac85a22..2ee0da2 100644
--- a/monitor/udisks2/gvfsudisks2utils.h
+++ b/monitor/udisks2/gvfsudisks2utils.h
@@ -57,7 +57,8 @@ void     gvfs_udisks2_unmount_notify_start (GMountOperation *op,
                                             GMount          *mount,
                                             GDrive          *drive,
                                             gboolean         generic_text);
-void     gvfs_udisks2_unmount_notify_stop  (GMountOperation *op);
+void     gvfs_udisks2_unmount_notify_stop  (GMountOperation *op,
+                                            gboolean         unmount_failed);
 
 G_END_DECLS
 


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