gvfs r1373 - in trunk: . daemon
- From: gicmo svn gnome org
- To: svn-commits-list gnome org
- Subject: gvfs r1373 - in trunk: . daemon
- Date: Mon, 25 Feb 2008 20:04:47 +0000 (GMT)
Author: gicmo
Date: Mon Feb 25 20:04:46 2008
New Revision: 1373
URL: http://svn.gnome.org/viewvc/gvfs?rev=1373&view=rev
Log:
2008-02-25 Christian Kellner <gicmo gnome org>
* daemon/gvfsbackenddav.c:
Initial take on implementing delete.
* daemon/gvfsbackendhttp.c:
* daemon/gvfsbackendhttp.h:
Add http_error_code_from_status helper function.
Modified:
trunk/ChangeLog
trunk/daemon/gvfsbackenddav.c
trunk/daemon/gvfsbackendhttp.c
trunk/daemon/gvfsbackendhttp.h
Modified: trunk/daemon/gvfsbackenddav.c
==============================================================================
--- trunk/daemon/gvfsbackenddav.c (original)
+++ trunk/daemon/gvfsbackenddav.c Mon Feb 25 20:04:46 2008
@@ -867,6 +867,53 @@
return res;
}
+static gboolean
+stat_location (GVfsBackend *backend,
+ const SoupURI *uri,
+ GFileType *target_type,
+ guint *num_children,
+ GError **error)
+{
+ SoupSession *session;
+ SoupMessage *msg;
+ guint status;
+ gboolean count_children;
+ gboolean res;
+
+ session = G_VFS_BACKEND_HTTP (backend)->session;
+
+ count_children = num_children != NULL;
+
+ msg = stat_location_begin (uri, count_children);
+
+ if (msg == NULL)
+ return FALSE;
+
+ status = soup_session_send_message (session, msg);
+
+ if (status != 207)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ http_error_code_from_status (status),
+ msg->reason_phrase);
+
+ return FALSE;
+ }
+
+ res = stat_location_finish (msg, target_type, num_children);
+
+ if (res == FALSE)
+ {
+ g_set_error (error,
+ G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Response invalid"));
+ }
+
+ return res;
+}
+
+
/* ************************************************************************* */
/* */
@@ -1586,7 +1633,6 @@
{
SoupMessage *msg;
guint status;
- char *to_free;
msg = message_new_from_filename_full (backend, "MKCOL", filename, TRUE);
@@ -1595,7 +1641,7 @@
/* TODO: error reporting sucks */
if (! SOUP_STATUS_IS_SUCCESSFUL (status))
g_vfs_job_failed (G_VFS_JOB (job),
- G_IO_ERROR,G_IO_ERROR_FAILED,
+ G_IO_ERROR, G_IO_ERROR_FAILED,
_("HTTP Error: %s"), msg->reason_phrase);
else
g_vfs_job_succeeded (G_VFS_JOB (job));
@@ -1603,6 +1649,55 @@
g_object_unref (msg);
}
+static void
+do_delete (GVfsBackend *backend,
+ GVfsJobDelete *job,
+ const char *filename)
+{
+ SoupSession *session;
+ SoupMessage *msg;
+ SoupURI *uri;
+ GFileType file_type;
+ gboolean res;
+ guint num_children;
+ guint status;
+ GError *error;
+
+ error = NULL;
+ session = G_VFS_BACKEND_HTTP (backend)->session;
+
+ uri = g_vfs_backend_uri_for_filename (backend, filename, FALSE);
+ res = stat_location (backend, uri, &file_type, &num_children, &error);
+
+ if (res == FALSE)
+ {
+ g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ return;
+ }
+
+ if (file_type == G_FILE_TYPE_DIRECTORY && num_children)
+ {
+ g_vfs_job_failed (G_VFS_JOB (job),
+ G_IO_ERROR, G_IO_ERROR_NOT_EMPTY,
+ _("Directory not empty"));
+ return;
+ }
+
+ msg = soup_message_new_from_uri (SOUP_METHOD_DELETE, uri);
+
+ status = soup_session_send_message (session, msg);
+
+ if (!SOUP_STATUS_IS_SUCCESSFUL (status))
+ g_vfs_job_failed (G_VFS_JOB (job),
+ G_IO_ERROR_NOT_EMPTY,
+ http_error_code_from_status (status),
+ msg->reason_phrase);
+ else
+ g_vfs_job_succeeded (G_VFS_JOB (job));
+
+ soup_uri_free (uri);
+ g_object_unref (msg);
+}
/* ************************************************************************* */
/* */
@@ -1628,4 +1723,5 @@
backend_class->try_write = try_write;
backend_class->try_close_write = try_close_write;
backend_class->make_directory = do_make_directory;
+ backend_class->delete = do_delete;
}
Modified: trunk/daemon/gvfsbackendhttp.c
==============================================================================
--- trunk/daemon/gvfsbackendhttp.c (original)
+++ trunk/daemon/gvfsbackendhttp.c Mon Feb 25 20:04:46 2008
@@ -165,6 +165,34 @@
/* ************************************************************************* */
/* */
+guint
+http_error_code_from_status (guint status)
+{
+ switch (status) {
+
+ case SOUP_STATUS_CANT_RESOLVE:
+ case SOUP_STATUS_CANT_RESOLVE_PROXY:
+ return G_IO_ERROR_HOST_NOT_FOUND;
+
+ case SOUP_STATUS_CANCELLED:
+ return G_IO_ERROR_CANCELLED;
+
+ case SOUP_STATUS_UNAUTHORIZED:
+ case SOUP_STATUS_PAYMENT_REQUIRED:
+ case SOUP_STATUS_FORBIDDEN:
+ return G_IO_ERROR_PERMISSION_DENIED;
+
+ case SOUP_STATUS_NOT_FOUND:
+ case SOUP_STATUS_GONE:
+ return G_IO_ERROR_NOT_FOUND;
+
+ case SOUP_STATUS_GATEWAY_TIMEOUT:
+ return G_IO_ERROR_TIMED_OUT;
+ }
+
+ return G_IO_ERROR_FAILED;
+}
+
static void
g_vfs_job_failed_from_http_status (GVfsJob *job, guint status_code, const char *message)
Modified: trunk/daemon/gvfsbackendhttp.h
==============================================================================
--- trunk/daemon/gvfsbackendhttp.h (original)
+++ trunk/daemon/gvfsbackendhttp.h Mon Feb 25 20:04:46 2008
@@ -70,6 +70,9 @@
SoupMessage * message_new_from_uri (const char *method,
SoupURI *uri);
char * uri_get_basename (const char *uri_str);
+
+guint http_error_code_from_status (guint status);
+
G_END_DECLS
#endif /* __G_VFS_BACKEND_HTTP_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]