[gvfs] gvfsjobunmount: set error as per client interaction



commit db89e2908ec3da88472fd80aea20382692d48217
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Sep 11 08:55:21 2014 +0200

    gvfsjobunmount: set error as per client interaction
    
    If the dialog about blocking processes was cancelled,
    G_IO_ERROR_FAILED_HANDLED will be returned. If there were outstanding
    jobs and GMountOperation wasn't passed in, or "show-processes" signal
    wasn't handled, G_IO_ERROR_BUSY will be returned.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710986

 daemon/gvfsbackend.c    |   30 +++++++++++++++++++++++-------
 daemon/gvfsbackend.h    |    3 ++-
 daemon/gvfsjobunmount.c |   30 ++++++++++++++++++++----------
 3 files changed, 45 insertions(+), 18 deletions(-)
---
diff --git a/daemon/gvfsbackend.c b/daemon/gvfsbackend.c
index 299a9bd..a143498 100644
--- a/daemon/gvfsbackend.c
+++ b/daemon/gvfsbackend.c
@@ -811,22 +811,32 @@ complete_unmount_with_op (UnmountWithOpData *data)
 
   ret = TRUE;
 
+  simple = g_simple_async_result_new (G_OBJECT (data->backend),
+                                      data->callback,
+                                      data->user_data,
+                                      NULL);
+
   if (data->no_more_processes)
     {
       /* do nothing, e.g. return TRUE to signal we should unmount */
     }
+  else if (!data->ret)
+    {
+      /*  If the "show-processes" signal wasn't handled */
+      g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_BUSY,
+                                       _("File system is busy"));
+      ret = FALSE;
+    }
   else
     {
       if (data->aborted || data->choice == 1)
         {
+          g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED,
+                                           "GMountOperation aborted");
           ret = FALSE;
         }
     }
 
-  simple = g_simple_async_result_new (G_OBJECT (data->backend),
-                                      data->callback,
-                                      data->user_data,
-                                      NULL);
   g_simple_async_result_set_op_res_gboolean (simple, ret);
   g_simple_async_result_complete (simple);
   g_object_unref (simple);
@@ -894,22 +904,28 @@ unmount_with_op_data_free (UnmountWithOpData *data)
  * @backend: A #GVfsBackend.
  * @res: A #GAsyncResult obtained from the @callback function passed
  *     to g_vfs_backend_unmount_with_operation().
+ * @error: A #GError, or NULL.
  *
  * Gets the result of the operation started by
  * gvfs_backend_unmount_with_operation_sync().
  *
+ * If the operation was cancelled, G_IO_ERROR_FAILED_HANDLED will be returned.
+ * If the operation wasn't interacted and there were outstanding jobs,
+ * G_IO_ERROR_BUSY will be returned.
+ *
  * Returns: %TRUE if the backend should be unmounted (either no blocking
  *     processes or the user decided to unmount anyway), %FALSE if
- *     no action should be taken.
+ *     no action should be taken (error is set).
  */
 gboolean
 g_vfs_backend_unmount_with_operation_finish (GVfsBackend *backend,
-                                             GAsyncResult *res)
+                                             GAsyncResult *res,
+                                             GError **error)
 {
   gboolean ret;
   GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
 
-  if (g_simple_async_result_propagate_error (simple, NULL))
+  if (g_simple_async_result_propagate_error (simple, error))
     {
       ret = FALSE;
     }
diff --git a/daemon/gvfsbackend.h b/daemon/gvfsbackend.h
index 82c8283..5908d43 100644
--- a/daemon/gvfsbackend.h
+++ b/daemon/gvfsbackend.h
@@ -515,7 +515,8 @@ void        g_vfs_backend_set_block_requests             (GVfsBackend
 gboolean    g_vfs_backend_get_block_requests             (GVfsBackend           *backend);
 
 gboolean    g_vfs_backend_unmount_with_operation_finish (GVfsBackend  *backend,
-                                                         GAsyncResult *res);
+                                                         GAsyncResult *res,
+                                                         GError      **error);
 
 void        g_vfs_backend_unmount_with_operation (GVfsBackend        *backend,
                                                   GMountSource       *mount_source,
diff --git a/daemon/gvfsjobunmount.c b/daemon/gvfsjobunmount.c
index 205407c..6da8d8b 100644
--- a/daemon/gvfsjobunmount.c
+++ b/daemon/gvfsjobunmount.c
@@ -210,13 +210,19 @@ unmount_cb (GVfsBackend  *backend,
   GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);
   gboolean should_unmount;
   gboolean finished;
+  GError *error = NULL;
 
   should_unmount = g_vfs_backend_unmount_with_operation_finish (backend,
-                                                                res);
-
-  if (should_unmount)
-    op_job->flags |= G_MOUNT_UNMOUNT_FORCE;
+                                                                res,
+                                                                &error);
+  if (!should_unmount)
+    {
+      g_vfs_job_failed_from_error (G_VFS_JOB (op_job), error);
+      g_error_free (error);
+      return;
+    }
 
+  op_job->flags |= G_MOUNT_UNMOUNT_FORCE;
   finished = job_finish_immediately_if_possible (op_job);
 
   if (! finished)
@@ -247,13 +253,17 @@ try (GVfsJob *job)
   is_busy = g_vfs_daemon_has_blocking_processes (g_vfs_backend_get_daemon (backend));
   force_unmount = op_job->flags & G_MOUNT_UNMOUNT_FORCE;
   
-  if (is_busy && ! force_unmount
-      && ! g_mount_source_is_dummy (op_job->mount_source))
+  if (is_busy && !force_unmount)
     {
-      g_vfs_backend_unmount_with_operation (backend,
-                                           op_job->mount_source,
-                                           (GAsyncReadyCallback) unmount_cb,
-                                           op_job);
+      if (g_mount_source_is_dummy (op_job->mount_source))
+        g_vfs_job_failed_literal (G_VFS_JOB (op_job),
+                                  G_IO_ERROR, G_IO_ERROR_BUSY,
+                                  _("File system is busy"));
+      else
+        g_vfs_backend_unmount_with_operation (backend,
+                                              op_job->mount_source,
+                                              (GAsyncReadyCallback)unmount_cb,
+                                              op_job);
       return TRUE;
     }
 


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