summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebarshi Ray <debarshir@gnome.org>2014-12-16 17:42:01 +0100
committerDebarshi Ray <debarshir@gnome.org>2014-12-16 18:58:19 +0100
commitc692d439f30c8dd47e14dd1fb2f2215c25747893 (patch)
tree97410ef894fde4ef6914d5d264de6bf22ac264b9
parent2066c47491b0e686a26d5f88937c47bf2e22b8c4 (diff)
downloadgvfs-wip/goa.tar.gz
Support g_file_resolve_created_path()wip/goa
https://bugzilla.gnome.org/show_bug.cgi?id=741602
-rw-r--r--client/gdaemonfile.c50
-rw-r--r--common/org.gtk.vfs.xml4
-rw-r--r--daemon/Makefile.am1
-rw-r--r--daemon/gvfsbackend.c2
-rw-r--r--daemon/gvfsbackend.h7
-rw-r--r--daemon/gvfsjobresolvecreatedpath.c144
-rw-r--r--daemon/gvfsjobresolvecreatedpath.h68
7 files changed, 276 insertions, 0 deletions
diff --git a/client/gdaemonfile.c b/client/gdaemonfile.c
index e97c9a4e..6834218c 100644
--- a/client/gdaemonfile.c
+++ b/client/gdaemonfile.c
@@ -1321,6 +1321,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;
@@ -3793,6 +3842,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 f8975d91..14ec4466 100644
--- a/common/org.gtk.vfs.xml
+++ b/common/org.gtk.vfs.xml
@@ -339,6 +339,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 bd54d64b..13a35c3a 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -192,6 +192,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 d2750dad..ffe1b90b 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 6f77cf9c..7f42819f 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 00000000..d4b2d5df
--- /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 00000000..a21681d3
--- /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__ */