[gvfs] afp: implement delete



commit b66b30a4dd60840f9aa6ebe4373141fd2f7bd344
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Sun Jul 3 21:18:28 2011 +0200

    afp: implement delete

 daemon/gvfsafpconnection.h |    5 ++-
 daemon/gvfsbackendafp.c    |   93 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 1 deletions(-)
---
diff --git a/daemon/gvfsafpconnection.h b/daemon/gvfsafpconnection.h
index 12451f3..be21cb8 100644
--- a/daemon/gvfsafpconnection.h
+++ b/daemon/gvfsafpconnection.h
@@ -129,6 +129,7 @@ typedef enum
 {
   AFP_COMMAND_CLOSE_FORK         = 4,
   AFP_COMMAND_CREATE_FILE        = 7,
+  AFP_COMMAND_DELETE             = 8,
   AFP_COMMAND_GET_FORK_PARMS     = 14,
   AFP_COMMAND_GET_SRVR_INFO      = 15,
   AFP_COMMAND_GET_SRVR_PARMS     = 16,
@@ -151,6 +152,7 @@ typedef enum
   AFP_RESULT_NO_MORE_SESSIONS    = -1068,
   AFP_RESULT_ACCESS_DENIED       = -5000, 
   AFP_RESULT_AUTH_CONTINUE       = -5001,
+  AFP_RESULT_DIR_NOT_EMPTY       = -5007,
   AFP_RESULT_DISK_FULL           = -5008,
   AFP_RESULT_EOF_ERR             = -5009,
   AFP_RESULT_FILE_BUSY           = -5010,
@@ -161,7 +163,8 @@ typedef enum
   AFP_RESULT_USER_NOT_AUTH       = -5023,
   AFP_RESULT_OBJECT_TYPE_ERR     = -5025,
   AFP_RESULT_TOO_MANY_FILES_OPEN = -5026,
-  AFP_RESULT_VOL_LOCKED          = -5031
+  AFP_RESULT_VOL_LOCKED          = -5031,
+  AFP_RESULT_OBJECT_LOCKED       = -5032
 } AfpResultCode;
 
 /*
diff --git a/daemon/gvfsbackendafp.c b/daemon/gvfsbackendafp.c
index 5d0e553..c035a5c 100644
--- a/daemon/gvfsbackendafp.c
+++ b/daemon/gvfsbackendafp.c
@@ -39,6 +39,7 @@
 #include "gvfsjobread.h"
 #include "gvfsjobseekread.h"
 #include "gvfsjobopenforwrite.h"
+#include "gvfsjobdelete.h"
 
 #include "gvfsafpserver.h"
 #include "gvfsafpconnection.h"
@@ -256,6 +257,97 @@ static void fill_info (GVfsBackendAfp *afp_backend,
 }
 
 static void
+delete_cb (GVfsAfpConnection *afp_connection,
+           GVfsAfpReply      *reply,
+           GError            *error,
+           gpointer           user_data)
+{
+  GVfsJobDelete *job = G_VFS_JOB_DELETE (user_data);
+
+  AfpResultCode res_code;
+  
+  if (!reply)
+  {
+    g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+    return;
+  }
+
+  res_code = g_vfs_afp_reply_get_result_code (reply);
+  if (res_code != AFP_RESULT_NO_ERROR)
+  {
+    g_object_unref (reply);
+
+    if (res_code == AFP_RESULT_ACCESS_DENIED)
+    {
+      g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+                                _("Access denied"));
+    }
+    else if (res_code == AFP_RESULT_DIR_NOT_EMPTY)
+    {
+      g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_EMPTY,
+                                _("Directory not empty"));
+    }
+    else if (res_code == AFP_RESULT_OBJECT_LOCKED)
+    {
+      g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
+                                _("Target object is marked as DeleteInhibit"));
+    }
+    else if (res_code == AFP_RESULT_OBJECT_NOT_FOUND)
+    {
+      g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+                                _("Target object doesn't exist"));
+    }
+    else if (res_code == AFP_RESULT_VOL_LOCKED)
+    {
+      g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+                                _("Volume is read-only"));
+    }
+    else
+    {
+      g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
+                        _("Got error code: %d from server"), res_code);
+    }
+    return;
+  }
+
+  g_vfs_job_succeeded (G_VFS_JOB (job));
+}
+
+static gboolean 
+try_delete (GVfsBackend *backend,
+            GVfsJobDelete *job,
+            const char *filename)
+{
+  GVfsBackendAfp *afp_backend = G_VFS_BACKEND_AFP (backend);
+
+  GVfsAfpCommand *comm;
+  GVfsAfpName *pathname;
+
+  comm = g_vfs_afp_command_new (AFP_COMMAND_DELETE);
+  /* pad byte */
+  g_data_output_stream_put_byte (G_DATA_OUTPUT_STREAM (comm), 0, NULL, NULL);
+  /* Volume ID */
+  g_data_output_stream_put_uint16 (G_DATA_OUTPUT_STREAM (comm),
+                                   afp_backend->volume_id, NULL, NULL);
+  /* Directory ID 2 == / */
+  g_data_output_stream_put_uint32 (G_DATA_OUTPUT_STREAM (comm), 2, NULL, NULL);
+  /* PathType */
+  g_data_output_stream_put_byte (G_DATA_OUTPUT_STREAM (comm), AFP_PATH_TYPE_UTF8_NAME,
+                                 NULL, NULL);
+
+  /* Pathname */
+  pathname = filename_to_afp_pathname (filename);
+  g_vfs_afp_command_put_afp_name (comm, pathname);
+  g_vfs_afp_name_unref (pathname);
+
+  g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm, delete_cb,
+                                      G_VFS_JOB (job)->cancellable, job);
+  g_object_unref (comm);
+
+  return TRUE;
+}
+
+static void
 seek_on_read_cb (GVfsAfpConnection *afp_connection,
                  GVfsAfpReply      *reply,
                  GError            *error,
@@ -1392,6 +1484,7 @@ g_vfs_backend_afp_class_init (GVfsBackendAfpClass *klass)
   backend_class->try_read = try_read;
   backend_class->try_seek_on_read = try_seek_on_read;
   backend_class->try_create = try_create;
+  backend_class->try_delete = try_delete;
 }
 
 void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]