summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@src.gnome.org>2007-09-13 14:00:05 +0000
committerAlexander Larsson <alexl@src.gnome.org>2007-09-13 14:00:05 +0000
commit2f8205a568181f5f63f565f11952e657afa5a3b2 (patch)
treeb8d8ffc67349912af4067344872d27042029e5ed /daemon
parent3abebe5d04882e632575182525bd61f374780a59 (diff)
downloadgvfs-2f8205a568181f5f63f565f11952e657afa5a3b2.tar.gz
Implement trash/delete in daemon
Original git commit by Alexander Larsson <alexl@redhat.com> at 1183468196 +0200 svn path=/trunk/; revision=610
Diffstat (limited to 'daemon')
-rw-r--r--daemon/Makefile.am2
-rw-r--r--daemon/gvfsbackend.c10
-rw-r--r--daemon/gvfsbackend.h14
-rw-r--r--daemon/gvfsbackendsmb.c21
-rw-r--r--daemon/gvfsjobdelete.c136
-rw-r--r--daemon/gvfsjobdelete.h41
-rw-r--r--daemon/gvfsjobtrash.c136
-rw-r--r--daemon/gvfsjobtrash.h41
8 files changed, 401 insertions, 0 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 6a341511..2165e893 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -72,6 +72,8 @@ libdaemon_la_SOURCES = \
gvfsjobgetfsinfo.c gvfsjobgetfsinfo.h \
gvfsjobenumerate.c gvfsjobenumerate.h \
gvfsjobsetdisplayname.c gvfsjobsetdisplayname.h \
+ gvfsjobtrash.c gvfsjobtrash.h \
+ gvfsjobdelete.c gvfsjobdelete.h \
gvfsdaemonprotocol.c \
dbus-gmain.h dbus-gmain.c \
$(NULL)
diff --git a/daemon/gvfsbackend.c b/daemon/gvfsbackend.c
index b63554bb..1802077d 100644
--- a/daemon/gvfsbackend.c
+++ b/daemon/gvfsbackend.c
@@ -18,6 +18,8 @@
#include <gvfsjobgetfsinfo.h>
#include <gvfsjobsetdisplayname.h>
#include <gvfsjobenumerate.h>
+#include <gvfsjobdelete.h>
+#include <gvfsjobtrash.h>
#include <gvfsjobmountmountable.h>
#include <gdbusutils.h>
@@ -282,6 +284,14 @@ backend_dbus_handler (DBusConnection *connection,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_SET_DISPLAY_NAME))
job = g_vfs_job_set_display_name_new (connection, message, backend);
+ else if (dbus_message_is_method_call (message,
+ G_VFS_DBUS_MOUNT_INTERFACE,
+ G_VFS_DBUS_MOUNT_OP_DELETE))
+ job = g_vfs_job_delete_new (connection, message, backend);
+ else if (dbus_message_is_method_call (message,
+ G_VFS_DBUS_MOUNT_INTERFACE,
+ G_VFS_DBUS_MOUNT_OP_TRASH))
+ job = g_vfs_job_trash_new (connection, message, backend);
if (job)
{
diff --git a/daemon/gvfsbackend.h b/daemon/gvfsbackend.h
index a593bd58..bb5ef9c7 100644
--- a/daemon/gvfsbackend.h
+++ b/daemon/gvfsbackend.h
@@ -37,6 +37,8 @@ typedef struct _GVfsJobGetInfo GVfsJobGetInfo;
typedef struct _GVfsJobGetFsInfo GVfsJobGetFsInfo;
typedef struct _GVfsJobEnumerate GVfsJobEnumerate;
typedef struct _GVfsJobSetDisplayName GVfsJobSetDisplayName;
+typedef struct _GVfsJobTrash GVfsJobTrash;
+typedef struct _GVfsJobDelete GVfsJobDelete;
typedef gpointer GVfsBackendHandle;
@@ -195,6 +197,18 @@ struct _GVfsBackendClass
GVfsJobSetDisplayName *job,
const char *filename,
const char *display_name);
+ void (*delete) (GVfsBackend *backend,
+ GVfsJobSetDisplayName *job,
+ const char *filename);
+ gboolean (*try_delete) (GVfsBackend *backend,
+ GVfsJobSetDisplayName *job,
+ const char *filename);
+ void (*trash) (GVfsBackend *backend,
+ GVfsJobSetDisplayName *job,
+ const char *filename);
+ gboolean (*try_trash) (GVfsBackend *backend,
+ GVfsJobSetDisplayName *job,
+ const char *filename);
};
GType g_vfs_backend_get_type (void) G_GNUC_CONST;
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
index 13652748..f03d9c52 100644
--- a/daemon/gvfsbackendsmb.c
+++ b/daemon/gvfsbackendsmb.c
@@ -1359,6 +1359,26 @@ do_set_display_name (GVfsBackend *backend,
}
static void
+do_delete (GVfsBackend *backend,
+ GVfsJobSetDisplayName *job,
+ const char *filename)
+{
+ GVfsBackendSmb *op_backend = G_VFS_BACKEND_SMB (backend);
+ char *uri;
+ int errsv, res;
+
+ uri = create_smb_uri (op_backend->server, op_backend->share, filename);
+ res = op_backend->smb_context->unlink (op_backend->smb_context, uri);
+ errsv = errno;
+ g_free (uri);
+
+ if (res != 0)
+ g_vfs_job_failed_from_errno (G_VFS_JOB (job), errsv);
+ else
+ g_vfs_job_succeeded (G_VFS_JOB (job));
+}
+
+static void
g_vfs_backend_smb_class_init (GVfsBackendSmbClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
@@ -1382,4 +1402,5 @@ g_vfs_backend_smb_class_init (GVfsBackendSmbClass *klass)
backend_class->get_fs_info = do_get_fs_info;
backend_class->enumerate = do_enumerate;
backend_class->set_display_name = do_set_display_name;
+ backend_class->delete = do_delete;
}
diff --git a/daemon/gvfsjobdelete.c b/daemon/gvfsjobdelete.c
new file mode 100644
index 00000000..1cda1580
--- /dev/null
+++ b/daemon/gvfsjobdelete.c
@@ -0,0 +1,136 @@
+#include <config.h>
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <glib.h>
+#include <dbus/dbus.h>
+#include <glib/gi18n.h>
+#include "gvfsjobdelete.h"
+#include "gdbusutils.h"
+#include "gvfsdaemonprotocol.h"
+
+G_DEFINE_TYPE (GVfsJobDelete, g_vfs_job_delete, G_VFS_TYPE_JOB_DBUS);
+
+static void run (GVfsJob *job);
+static gboolean try (GVfsJob *job);
+static DBusMessage *create_reply (GVfsJob *job,
+ DBusConnection *connection,
+ DBusMessage *message);
+
+static void
+g_vfs_job_delete_finalize (GObject *object)
+{
+ GVfsJobDelete *job;
+
+ job = G_VFS_JOB_DELETE (object);
+
+ g_free (job->filename);
+
+ if (G_OBJECT_CLASS (g_vfs_job_delete_parent_class)->finalize)
+ (*G_OBJECT_CLASS (g_vfs_job_delete_parent_class)->finalize) (object);
+}
+
+static void
+g_vfs_job_delete_class_init (GVfsJobDeleteClass *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_delete_finalize;
+ job_class->run = run;
+ job_class->try = try;
+ job_dbus_class->create_reply = create_reply;
+}
+
+static void
+g_vfs_job_delete_init (GVfsJobDelete *job)
+{
+}
+
+GVfsJob *
+g_vfs_job_delete_new (DBusConnection *connection,
+ DBusMessage *message,
+ GVfsBackend *backend)
+{
+ GVfsJobDelete *job;
+ DBusMessage *reply;
+ DBusError derror;
+ int path_len;
+ const char *path_data;
+
+ dbus_error_init (&derror);
+ if (!dbus_message_get_args (message, &derror,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+ &path_data, &path_len,
+ 0))
+ {
+ reply = dbus_message_new_error (message,
+ derror.name,
+ derror.message);
+ dbus_error_free (&derror);
+
+ dbus_connection_send (connection, reply, NULL);
+ return NULL;
+ }
+
+ job = g_object_new (G_VFS_TYPE_JOB_DELETE,
+ "message", message,
+ "connection", connection,
+ NULL);
+
+ job->filename = g_strndup (path_data, path_len);
+ job->backend = backend;
+
+ return G_VFS_JOB (job);
+}
+
+static void
+run (GVfsJob *job)
+{
+ GVfsJobDelete *op_job = G_VFS_JOB_DELETE (job);
+ GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);
+
+ if (class->delete == NULL)
+ {
+ g_vfs_job_failed (job, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation not supported by backend"));
+ return;
+ }
+
+ class->delete (op_job->backend,
+ op_job,
+ op_job->filename);
+}
+
+static gboolean
+try (GVfsJob *job)
+{
+ GVfsJobDelete *op_job = G_VFS_JOB_DELETE (job);
+ GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);
+
+ if (class->try_delete == NULL)
+ return FALSE;
+
+ return class->try_delete (op_job->backend,
+ op_job,
+ op_job->filename);
+}
+
+/* Might be called on an i/o thread */
+static DBusMessage *
+create_reply (GVfsJob *job,
+ DBusConnection *connection,
+ DBusMessage *message)
+{
+ GVfsJobDelete *op_job = G_VFS_JOB_DELETE (job);
+ DBusMessage *reply;
+ DBusMessageIter iter;
+
+ reply = dbus_message_new_method_return (message);
+
+ return reply;
+}
diff --git a/daemon/gvfsjobdelete.h b/daemon/gvfsjobdelete.h
new file mode 100644
index 00000000..c53f6889
--- /dev/null
+++ b/daemon/gvfsjobdelete.h
@@ -0,0 +1,41 @@
+#ifndef __G_VFS_JOB_DELETE_H__
+#define __G_VFS_JOB_DELETE_H__
+
+#include <gio/gfileinfo.h>
+#include <gvfsjob.h>
+#include <gvfsjobdbus.h>
+#include <gvfsbackend.h>
+
+G_BEGIN_DECLS
+
+#define G_VFS_TYPE_JOB_DELETE (g_vfs_job_delete_get_type ())
+#define G_VFS_JOB_DELETE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_VFS_TYPE_JOB_DELETE, GVfsJobDelete))
+#define G_VFS_JOB_DELETE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_VFS_TYPE_JOB_DELETE, GVfsJobDeleteClass))
+#define G_VFS_IS_JOB_DELETE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_VFS_TYPE_JOB_DELETE))
+#define G_VFS_IS_JOB_DELETE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_VFS_TYPE_JOB_DELETE))
+#define G_VFS_JOB_DELETE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_VFS_TYPE_JOB_DELETE, GVfsJobDeleteClass))
+
+typedef struct _GVfsJobDeleteClass GVfsJobDeleteClass;
+
+struct _GVfsJobDelete
+{
+ GVfsJobDBus parent_instance;
+
+ GVfsBackend *backend;
+ char *filename;
+};
+
+struct _GVfsJobDeleteClass
+{
+ GVfsJobDBusClass parent_class;
+};
+
+GType g_vfs_job_delete_get_type (void) G_GNUC_CONST;
+
+GVfsJob *g_vfs_job_delete_new (DBusConnection *connection,
+ DBusMessage *message,
+ GVfsBackend *backend);
+
+G_END_DECLS
+
+#endif /* __G_VFS_JOB_DELETE_H__ */
diff --git a/daemon/gvfsjobtrash.c b/daemon/gvfsjobtrash.c
new file mode 100644
index 00000000..0129c8be
--- /dev/null
+++ b/daemon/gvfsjobtrash.c
@@ -0,0 +1,136 @@
+#include <config.h>
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <glib.h>
+#include <dbus/dbus.h>
+#include <glib/gi18n.h>
+#include "gvfsjobtrash.h"
+#include "gdbusutils.h"
+#include "gvfsdaemonprotocol.h"
+
+G_DEFINE_TYPE (GVfsJobTrash, g_vfs_job_trash, G_VFS_TYPE_JOB_DBUS);
+
+static void run (GVfsJob *job);
+static gboolean try (GVfsJob *job);
+static DBusMessage *create_reply (GVfsJob *job,
+ DBusConnection *connection,
+ DBusMessage *message);
+
+static void
+g_vfs_job_trash_finalize (GObject *object)
+{
+ GVfsJobTrash *job;
+
+ job = G_VFS_JOB_TRASH (object);
+
+ g_free (job->filename);
+
+ if (G_OBJECT_CLASS (g_vfs_job_trash_parent_class)->finalize)
+ (*G_OBJECT_CLASS (g_vfs_job_trash_parent_class)->finalize) (object);
+}
+
+static void
+g_vfs_job_trash_class_init (GVfsJobTrashClass *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_trash_finalize;
+ job_class->run = run;
+ job_class->try = try;
+ job_dbus_class->create_reply = create_reply;
+}
+
+static void
+g_vfs_job_trash_init (GVfsJobTrash *job)
+{
+}
+
+GVfsJob *
+g_vfs_job_trash_new (DBusConnection *connection,
+ DBusMessage *message,
+ GVfsBackend *backend)
+{
+ GVfsJobTrash *job;
+ DBusMessage *reply;
+ DBusError derror;
+ int path_len;
+ const char *path_data;
+
+ dbus_error_init (&derror);
+ if (!dbus_message_get_args (message, &derror,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+ &path_data, &path_len,
+ 0))
+ {
+ reply = dbus_message_new_error (message,
+ derror.name,
+ derror.message);
+ dbus_error_free (&derror);
+
+ dbus_connection_send (connection, reply, NULL);
+ return NULL;
+ }
+
+ job = g_object_new (G_VFS_TYPE_JOB_TRASH,
+ "message", message,
+ "connection", connection,
+ NULL);
+
+ job->filename = g_strndup (path_data, path_len);
+ job->backend = backend;
+
+ return G_VFS_JOB (job);
+}
+
+static void
+run (GVfsJob *job)
+{
+ GVfsJobTrash *op_job = G_VFS_JOB_TRASH (job);
+ GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);
+
+ if (class->trash == NULL)
+ {
+ g_vfs_job_failed (job, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation not supported by backend"));
+ return;
+ }
+
+ class->trash (op_job->backend,
+ op_job,
+ op_job->filename);
+}
+
+static gboolean
+try (GVfsJob *job)
+{
+ GVfsJobTrash *op_job = G_VFS_JOB_TRASH (job);
+ GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);
+
+ if (class->try_trash == NULL)
+ return FALSE;
+
+ return class->try_trash (op_job->backend,
+ op_job,
+ op_job->filename);
+}
+
+/* Might be called on an i/o thread */
+static DBusMessage *
+create_reply (GVfsJob *job,
+ DBusConnection *connection,
+ DBusMessage *message)
+{
+ GVfsJobTrash *op_job = G_VFS_JOB_TRASH (job);
+ DBusMessage *reply;
+ DBusMessageIter iter;
+
+ reply = dbus_message_new_method_return (message);
+
+ return reply;
+}
diff --git a/daemon/gvfsjobtrash.h b/daemon/gvfsjobtrash.h
new file mode 100644
index 00000000..1301f203
--- /dev/null
+++ b/daemon/gvfsjobtrash.h
@@ -0,0 +1,41 @@
+#ifndef __G_VFS_JOB_TRASH_H__
+#define __G_VFS_JOB_TRASH_H__
+
+#include <gio/gfileinfo.h>
+#include <gvfsjob.h>
+#include <gvfsjobdbus.h>
+#include <gvfsbackend.h>
+
+G_BEGIN_DECLS
+
+#define G_VFS_TYPE_JOB_TRASH (g_vfs_job_trash_get_type ())
+#define G_VFS_JOB_TRASH(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_VFS_TYPE_JOB_TRASH, GVfsJobTrash))
+#define G_VFS_JOB_TRASH_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_VFS_TYPE_JOB_TRASH, GVfsJobTrashClass))
+#define G_VFS_IS_JOB_TRASH(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_VFS_TYPE_JOB_TRASH))
+#define G_VFS_IS_JOB_TRASH_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_VFS_TYPE_JOB_TRASH))
+#define G_VFS_JOB_TRASH_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_VFS_TYPE_JOB_TRASH, GVfsJobTrashClass))
+
+typedef struct _GVfsJobTrashClass GVfsJobTrashClass;
+
+struct _GVfsJobTrash
+{
+ GVfsJobDBus parent_instance;
+
+ GVfsBackend *backend;
+ char *filename;
+};
+
+struct _GVfsJobTrashClass
+{
+ GVfsJobDBusClass parent_class;
+};
+
+GType g_vfs_job_trash_get_type (void) G_GNUC_CONST;
+
+GVfsJob *g_vfs_job_trash_new (DBusConnection *connection,
+ DBusMessage *message,
+ GVfsBackend *backend);
+
+G_END_DECLS
+
+#endif /* __G_VFS_JOB_TRASH_H__ */