[gvfs/wip/udisks2] Map UDisksError to GIOError and use FAILED_HANDLED for dismissed polkit dialogs
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/wip/udisks2] Map UDisksError to GIOError and use FAILED_HANDLED for dismissed polkit dialogs
- Date: Wed, 28 Sep 2011 21:28:37 +0000 (UTC)
commit f3f6a9a10ce427001805849e6e74959154cf27dc
Author: David Zeuthen <davidz redhat com>
Date: Wed Sep 28 17:27:34 2011 -0400
Map UDisksError to GIOError and use FAILED_HANDLED for dismissed polkit dialogs
Signed-off-by: David Zeuthen <davidz redhat com>
monitor/udisks2/Makefile.am | 1 +
monitor/udisks2/gvfsudisks2drive.c | 9 ++++-
monitor/udisks2/gvfsudisks2mount.c | 9 +----
monitor/udisks2/gvfsudisks2utils.c | 66 +++++++++++++++++++++++++++++++++++
monitor/udisks2/gvfsudisks2utils.h | 38 ++++++++++++++++++++
monitor/udisks2/gvfsudisks2volume.c | 2 +
6 files changed, 116 insertions(+), 9 deletions(-)
---
diff --git a/monitor/udisks2/Makefile.am b/monitor/udisks2/Makefile.am
index 890b252..f919df6 100644
--- a/monitor/udisks2/Makefile.am
+++ b/monitor/udisks2/Makefile.am
@@ -9,6 +9,7 @@ gvfs_udisks2_volume_monitor_SOURCES = \
gvfsudisks2drive.c gvfsudisks2drive.h \
gvfsudisks2volume.c gvfsudisks2volume.h \
gvfsudisks2mount.c gvfsudisks2mount.h \
+ gvfsudisks2utils.c gvfsudisks2utils.h \
$(NULL)
gvfs_udisks2_volume_monitor_CFLAGS = \
diff --git a/monitor/udisks2/gvfsudisks2drive.c b/monitor/udisks2/gvfsudisks2drive.c
index 9ceb1ad..c570a7d 100644
--- a/monitor/udisks2/gvfsudisks2drive.c
+++ b/monitor/udisks2/gvfsudisks2drive.c
@@ -33,6 +33,7 @@
#include "gvfsudisks2volumemonitor.h"
#include "gvfsudisks2drive.h"
#include "gvfsudisks2volume.h"
+#include "gvfsudisks2utils.h"
typedef struct _GVfsUDisks2DriveClass GVfsUDisks2DriveClass;
@@ -490,13 +491,16 @@ unmount_mounts_cb (GObject *source_object,
if (!g_mount_unmount_with_operation_finish (mount, res, &error))
{
/* make the error dialog more targeted to the drive.. unless the user has already seen a dialog */
- if (error->code != G_IO_ERROR_FAILED_HANDLED)
+ if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_BUSY)
{
g_error_free (error);
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_BUSY,
+ error = g_error_new (G_IO_ERROR,
+ G_IO_ERROR_BUSY,
_("Failed to eject medium; one or more volumes on the medium are busy."));
}
+ g_debug ("error: %s (%s, %d)", error->message, g_quark_to_string (error->domain), error->code);
+
/* unmount failed; need to fail the whole eject operation */
simple = g_simple_async_result_new_from_error (G_OBJECT (data->drive),
data->callback,
@@ -579,6 +583,7 @@ eject_cb (GObject *source_object,
error = NULL;
if (!udisks_drive_call_eject_finish (UDISKS_DRIVE (source_object), res, &error))
{
+ gvfs_udisks2_utils_udisks_error_to_gio_error (error);
g_simple_async_result_take_error (data->simple, error);
g_simple_async_result_complete (data->simple);
goto out;
diff --git a/monitor/udisks2/gvfsudisks2mount.c b/monitor/udisks2/gvfsudisks2mount.c
index 81f7682..8453246 100644
--- a/monitor/udisks2/gvfsudisks2mount.c
+++ b/monitor/udisks2/gvfsudisks2mount.c
@@ -42,6 +42,7 @@
#include "gvfsudisks2volumemonitor.h"
#include "gvfsudisks2mount.h"
#include "gvfsudisks2volume.h"
+#include "gvfsudisks2utils.h"
#define BUSY_UNMOUNT_NUM_ATTEMPTS 5
#define BUSY_UNMOUNT_MS_DELAY_BETWEEN_ATTEMPTS 100
@@ -670,13 +671,7 @@ unmount_cb (GObject *source_object,
res,
&error))
{
- /* translate to UDisksError to GIOError and strip D-Bus error information */
- if (error->domain == UDISKS_ERROR && error->code == UDISKS_ERROR_DEVICE_BUSY)
- error->code = G_IO_ERROR_BUSY;
- else
- error->code = G_IO_ERROR_FAILED;
- error->domain = G_IO_ERROR;
- g_dbus_error_strip_remote_error (error);
+ gvfs_udisks2_utils_udisks_error_to_gio_error (error);
/* if the user passed in a GMountOperation, then do the GMountOperation::show-processes dance ... */
if (error->code == G_IO_ERROR_BUSY && data->mount_operation != NULL)
diff --git a/monitor/udisks2/gvfsudisks2utils.c b/monitor/udisks2/gvfsudisks2utils.c
new file mode 100644
index 0000000..4cd8ca4
--- /dev/null
+++ b/monitor/udisks2/gvfsudisks2utils.c
@@ -0,0 +1,66 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* gvfs - extensions for gio
+ *
+ * Copyright (C) 2006-2009 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#include <config.h>
+
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+#include <gio/gio.h>
+
+#include "gvfsudisks2utils.h"
+
+void
+gvfs_udisks2_utils_udisks_error_to_gio_error (GError *error)
+{
+ g_return_if_fail (error != NULL);
+
+ if (error->domain == UDISKS_ERROR)
+ {
+ switch (error->code)
+ {
+ case UDISKS_ERROR_DEVICE_BUSY:
+ error->code = G_IO_ERROR_BUSY;
+ break;
+ case UDISKS_ERROR_NOT_AUTHORIZED_DISMISSED:
+ error->code = G_IO_ERROR_FAILED_HANDLED;
+ break;
+ default:
+ error->code = G_IO_ERROR_FAILED;
+ break;
+ }
+ }
+ else
+ {
+ error->code = G_IO_ERROR_FAILED;
+ }
+
+ error->domain = G_IO_ERROR;
+ g_dbus_error_strip_remote_error (error);
+}
+
diff --git a/monitor/udisks2/gvfsudisks2utils.h b/monitor/udisks2/gvfsudisks2utils.h
new file mode 100644
index 0000000..37b3cf1
--- /dev/null
+++ b/monitor/udisks2/gvfsudisks2utils.h
@@ -0,0 +1,38 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* gvfs - extensions for gio
+ *
+ * Copyright (C) 2006-2009 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#ifndef __GVFS_UDISKS2_UTILS_H__
+#define __GVFS_UDISKS2_UTILS_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include "gvfsudisks2volumemonitor.h"
+
+G_BEGIN_DECLS
+
+void gvfs_udisks2_utils_udisks_error_to_gio_error (GError *error);
+
+G_END_DECLS
+
+#endif /* __GVFS_UDISKS2_UTILS_H__ */
diff --git a/monitor/udisks2/gvfsudisks2volume.c b/monitor/udisks2/gvfsudisks2volume.c
index d2b1537..151a889 100644
--- a/monitor/udisks2/gvfsudisks2volume.c
+++ b/monitor/udisks2/gvfsudisks2volume.c
@@ -34,6 +34,7 @@
#include "gvfsudisks2drive.h"
#include "gvfsudisks2volume.h"
#include "gvfsudisks2mount.h"
+#include "gvfsudisks2utils.h"
typedef struct _GVfsUDisks2VolumeClass GVfsUDisks2VolumeClass;
@@ -549,6 +550,7 @@ mount_cb (GObject *source_object,
res,
&error))
{
+ gvfs_udisks2_utils_udisks_error_to_gio_error (error);
g_simple_async_result_take_error (data->simple, error);
g_simple_async_result_complete (data->simple);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]