[gvfs/wip/rishi/goa: 3/4] Support g_file_resolve_created_path()
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/wip/rishi/goa: 3/4] Support g_file_resolve_created_path()
- Date: Wed, 24 Jun 2015 11:40:25 +0000 (UTC)
commit 72aa56b3ebdcfca99f859ed341d8f1153c3cf516
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Dec 16 17:42:01 2014 +0100
Support g_file_resolve_created_path()
https://bugzilla.gnome.org/show_bug.cgi?id=741602
client/gdaemonfile.c | 50 ++++++++++++
common/org.gtk.vfs.xml | 4 +
daemon/Makefile.am | 1 +
daemon/gvfsbackend.c | 2 +
daemon/gvfsbackend.h | 7 ++
daemon/gvfsjobresolvecreatedpath.c | 144 ++++++++++++++++++++++++++++++++++++
daemon/gvfsjobresolvecreatedpath.h | 68 +++++++++++++++++
7 files changed, 276 insertions(+), 0 deletions(-)
---
diff --git a/client/gdaemonfile.c b/client/gdaemonfile.c
index cc9edea..5bc533c 100644
--- a/client/gdaemonfile.c
+++ b/client/gdaemonfile.c
@@ -1330,6 +1330,55 @@ g_daemon_file_replace (GFile *file,
return file_open_write (file, 2, etag, make_backup, flags, cancellable, error);
}
+static GFile *
+g_daemon_file_resolve_created_path (GFile *file,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GDaemonFile *daemon_file;
+ GMountInfo *mount_info;
+ char *new_path;
+ GVfsDBusMount *proxy;
+ char *path;
+ gboolean res;
+ GError *local_error = NULL;
+
+ daemon_file = G_DAEMON_FILE (file);
+ mount_info = NULL;
+
+ proxy = create_proxy_for_file (file, &mount_info, &path, NULL, cancellable, error);
+ if (proxy == NULL)
+ return NULL;
+
+ res = gvfs_dbus_mount_call_resolve_created_path_sync (proxy,
+ path,
+ &new_path,
+ cancellable,
+ &local_error);
+
+ if (! res)
+ {
+ if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ _g_dbus_send_cancelled_sync (g_dbus_proxy_get_connection (G_DBUS_PROXY (proxy)));
+ _g_propagate_error_stripped (error, local_error);
+
+ file = NULL;
+ }
+
+ g_free (path);
+ g_object_unref (proxy);
+
+ if(! res)
+ goto out;
+
+ g_mount_info_apply_prefix (mount_info, &new_path);
+ file = new_file_for_new_path (daemon_file, new_path);
+ g_free (new_path);
+
+ out:
+ g_mount_info_unref (mount_info);
+ return file;
+}
typedef struct {
GSimpleAsyncResult *result;
@@ -3816,6 +3865,7 @@ g_daemon_file_file_iface_init (GFileIface *iface)
iface->make_symbolic_link = g_daemon_file_make_symbolic_link;
iface->monitor_dir = g_daemon_file_monitor_dir;
iface->monitor_file = g_daemon_file_monitor_file;
+ iface->resolve_created_path = g_daemon_file_resolve_created_path;
iface->start_mountable = g_daemon_file_start_mountable;
iface->start_mountable_finish = g_daemon_file_start_mountable_finish;
iface->stop_mountable = g_daemon_file_stop_mountable;
diff --git a/common/org.gtk.vfs.xml b/common/org.gtk.vfs.xml
index 5030bb5..176251c 100644
--- a/common/org.gtk.vfs.xml
+++ b/common/org.gtk.vfs.xml
@@ -342,6 +342,10 @@
<arg type='b' name='can_seek' direction='out'/>
<annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
</method>
+ <method name="ResolveCreatedPath">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='ay' name='new_path' direction='out'/>
+ </method>
</interface>
<!--
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index c10a924..1be228f 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -183,6 +183,7 @@ libgvfsdaemon_la_SOURCES = \
gvfsjobqueryinfowrite.c gvfsjobqueryinfowrite.h \
gvfsjobqueryfsinfo.c gvfsjobqueryfsinfo.h \
gvfsjobenumerate.c gvfsjobenumerate.h \
+ gvfsjobresolvecreatedpath.c gvfsjobresolvecreatedpath.h \
gvfsjobsetdisplayname.c gvfsjobsetdisplayname.h \
gvfsjobtrash.c gvfsjobtrash.h \
gvfsjobdelete.c gvfsjobdelete.h \
diff --git a/daemon/gvfsbackend.c b/daemon/gvfsbackend.c
index d2750da..ffe1b90 100644
--- a/daemon/gvfsbackend.c
+++ b/daemon/gvfsbackend.c
@@ -37,6 +37,7 @@
#include <gvfsjobopenforwrite.h>
#include <gvfsjobqueryinfo.h>
#include <gvfsjobqueryfsinfo.h>
+#include <gvfsjobresolvecreatedpath.h>
#include <gvfsjobsetdisplayname.h>
#include <gvfsjobenumerate.h>
#include <gvfsjobdelete.h>
@@ -288,6 +289,7 @@ register_path_cb (GDBusConnection *conn,
g_signal_connect (skeleton, "handle-create-directory-monitor", G_CALLBACK
(g_vfs_job_create_directory_monitor_new_handle), data);
g_signal_connect (skeleton, "handle-create-file-monitor", G_CALLBACK
(g_vfs_job_create_file_monitor_new_handle), data);
g_signal_connect (skeleton, "handle-open-icon-for-read", G_CALLBACK
(g_vfs_job_open_icon_for_read_new_handle), data);
+ g_signal_connect (skeleton, "handle-resolve-created-path", G_CALLBACK
(g_vfs_job_resolve_created_path_new_handle), data);
error = NULL;
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton),
diff --git a/daemon/gvfsbackend.h b/daemon/gvfsbackend.h
index 6f77cf9..7f42819 100644
--- a/daemon/gvfsbackend.h
+++ b/daemon/gvfsbackend.h
@@ -62,6 +62,7 @@ typedef struct _GVfsJobQueryInfoRead GVfsJobQueryInfoRead;
typedef struct _GVfsJobQueryInfoWrite GVfsJobQueryInfoWrite;
typedef struct _GVfsJobQueryFsInfo GVfsJobQueryFsInfo;
typedef struct _GVfsJobEnumerate GVfsJobEnumerate;
+typedef struct _GVfsJobResolveCreatedPath GVfsJobResolveCreatedPath;
typedef struct _GVfsJobSetDisplayName GVfsJobSetDisplayName;
typedef struct _GVfsJobTrash GVfsJobTrash;
typedef struct _GVfsJobDelete GVfsJobDelete;
@@ -433,6 +434,12 @@ struct _GVfsBackendClass
gboolean (*try_query_writable_namespaces) (GVfsBackend *backend,
GVfsJobQueryAttributes *job,
const char *filename);
+ void (*resolve_created_path) (GVfsBackend *backend,
+ GVfsJobResolveCreatedPath *job,
+ const char *filename);
+ gboolean (*try_resolve_created_path) (GVfsBackend *backend,
+ GVfsJobResolveCreatedPath *job,
+ const char *filename);
void (*start_mountable) (GVfsBackend *backend,
GVfsJobStartMountable *job,
diff --git a/daemon/gvfsjobresolvecreatedpath.c b/daemon/gvfsjobresolvecreatedpath.c
new file mode 100644
index 0000000..d4b2d5d
--- /dev/null
+++ b/daemon/gvfsjobresolvecreatedpath.c
@@ -0,0 +1,144 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2014 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Debarshi Ray <debarshir gnome org>
+ */
+
+#include <config.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include "gvfsjobresolvecreatedpath.h"
+
+G_DEFINE_TYPE (GVfsJobResolveCreatedPath, g_vfs_job_resolve_created_path, G_VFS_TYPE_JOB_DBUS)
+
+static void run (GVfsJob *job);
+static gboolean try (GVfsJob *job);
+static void create_reply (GVfsJob *job,
+ GVfsDBusMount *object,
+ GDBusMethodInvocation *invocation);
+
+static void
+g_vfs_job_resolve_created_path_finalize (GObject *object)
+{
+ GVfsJobResolveCreatedPath *job;
+
+ job = G_VFS_JOB_RESOLVE_CREATED_PATH (object);
+
+ g_free (job->filename);
+ g_free (job->new_path);
+
+ if (G_OBJECT_CLASS (g_vfs_job_resolve_created_path_parent_class)->finalize)
+ (*G_OBJECT_CLASS (g_vfs_job_resolve_created_path_parent_class)->finalize) (object);
+}
+
+static void
+g_vfs_job_resolve_created_path_class_init (GVfsJobResolveCreatedPathClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GVfsJobClass *job_class = G_VFS_JOB_CLASS (klass);
+ GVfsJobDBusClass *job_dbus_class = G_VFS_JOB_DBUS_CLASS (klass);
+
+ gobject_class->finalize = g_vfs_job_resolve_created_path_finalize;
+ job_class->run = run;
+ job_class->try = try;
+ job_dbus_class->create_reply = create_reply;
+}
+
+static void
+g_vfs_job_resolve_created_path_init (GVfsJobResolveCreatedPath *job)
+{
+}
+
+gboolean
+g_vfs_job_resolve_created_path_new_handle (GVfsDBusMount *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *arg_path_data,
+ GVfsBackend *backend)
+{
+ GVfsJobResolveCreatedPath *job;
+
+ if (g_vfs_backend_invocation_first_handler (object, invocation, backend))
+ return TRUE;
+
+ job = g_object_new (G_VFS_TYPE_JOB_RESOLVE_CREATED_PATH,
+ "object", object,
+ "invocation", invocation,
+ NULL);
+
+ job->filename = g_strdup (arg_path_data);
+ job->backend = backend;
+
+ g_vfs_job_source_new_job (G_VFS_JOB_SOURCE (backend), G_VFS_JOB (job));
+ g_object_unref (job);
+
+ return TRUE;
+}
+
+static void
+run (GVfsJob *job)
+{
+ GVfsJobResolveCreatedPath *op_job = G_VFS_JOB_RESOLVE_CREATED_PATH (job);
+ GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);
+
+ if (class->resolve_created_path == NULL)
+ {
+ g_vfs_job_failed (job, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation not supported by backend"));
+ return;
+ }
+
+ class->resolve_created_path (op_job->backend,
+ op_job,
+ op_job->filename);
+}
+
+static gboolean
+try (GVfsJob *job)
+{
+ GVfsJobResolveCreatedPath *op_job = G_VFS_JOB_RESOLVE_CREATED_PATH (job);
+ GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);
+
+ if (class->try_resolve_created_path == NULL)
+ return FALSE;
+
+ return class->try_resolve_created_path (op_job->backend,
+ op_job,
+ op_job->filename);
+}
+
+void
+g_vfs_job_resolve_created_path_set_new_path (GVfsJobResolveCreatedPath *job,
+ const char *new_path)
+{
+ job->new_path = g_strdup (new_path);
+}
+
+/* Might be called on an i/o thread */
+static void
+create_reply (GVfsJob *job,
+ GVfsDBusMount *object,
+ GDBusMethodInvocation *invocation)
+{
+ GVfsJobResolveCreatedPath *op_job = G_VFS_JOB_RESOLVE_CREATED_PATH (job);
+
+ g_assert (op_job->new_path != NULL);
+
+ gvfs_dbus_mount_complete_resolve_created_path (object, invocation, op_job->new_path);
+}
diff --git a/daemon/gvfsjobresolvecreatedpath.h b/daemon/gvfsjobresolvecreatedpath.h
new file mode 100644
index 0000000..a21681d
--- /dev/null
+++ b/daemon/gvfsjobresolvecreatedpath.h
@@ -0,0 +1,68 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2014 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Debarshi Ray <debarshir gnome org>
+ */
+
+#ifndef __G_VFS_JOB_RESOLVE_CREATED_PATH_H__
+#define __G_VFS_JOB_RESOLVE_CREATED_PATH_H__
+
+#include <gio/gio.h>
+#include <gvfsjob.h>
+#include <gvfsjobdbus.h>
+#include <gvfsbackend.h>
+
+G_BEGIN_DECLS
+
+#define G_VFS_TYPE_JOB_RESOLVE_CREATED_PATH (g_vfs_job_resolve_created_path_get_type ())
+#define G_VFS_JOB_RESOLVE_CREATED_PATH(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
G_VFS_TYPE_JOB_RESOLVE_CREATED_PATH, GVfsJobResolveCreatedPath))
+#define G_VFS_JOB_RESOLVE_CREATED_PATH_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k),
G_VFS_TYPE_JOB_RESOLVE_CREATED_PATH, GVfsJobResolveCreatedPathClass))
+#define G_VFS_IS_JOB_RESOLVE_CREATED_PATH(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o),
G_VFS_TYPE_JOB_RESOLVE_CREATED_PATH))
+#define G_VFS_IS_JOB_RESOLVE_CREATED_PATH_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k),
G_VFS_TYPE_JOB_RESOLVE_CREATED_PATH))
+#define G_VFS_JOB_RESOLVE_CREATED_PATH_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),
G_VFS_TYPE_JOB_RESOLVE_CREATED_PATH, GVfsJobResolveCreatedPathClass))
+
+typedef struct _GVfsJobResolveCreatedPathClass GVfsJobResolveCreatedPathClass;
+
+struct _GVfsJobResolveCreatedPath
+{
+ GVfsJobDBus parent_instance;
+
+ GVfsBackend *backend;
+ char *filename;
+
+ char *new_path;
+};
+
+struct _GVfsJobResolveCreatedPathClass
+{
+ GVfsJobDBusClass parent_class;
+};
+
+GType g_vfs_job_resolve_created_path_get_type (void) G_GNUC_CONST;
+
+gboolean g_vfs_job_resolve_created_path_new_handle (GVfsDBusMount *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *arg_path_data,
+ GVfsBackend *backend);
+void g_vfs_job_resolve_created_path_set_new_path (GVfsJobResolveCreatedPath *job,
+ const char *new_path);
+
+G_END_DECLS
+
+#endif /* __G_VFS_JOB_RESOLVE_CREATED_PATH_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]