[gvfs] sftp: return proper error on mkdir when directory exists
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gvfs] sftp: return proper error on mkdir when directory exists
- Date: Fri, 21 Aug 2009 18:42:35 +0000 (UTC)
commit e32c48892a0b714b2d3169709453ee3a6a55114b
Author: Tomas Bzatek <tbzatek redhat com>
Date: Fri Aug 21 17:55:31 2009 +0200
sftp: return proper error on mkdir when directory exists
Nautilus depends on properly reported errors when an operation fails.
In this case, user was not able to create new directory on sftp share
when "untitled folder" already existed.
SFTP only returns generic SSH_FX_FAILURE code so let's do SSH_FXP_LSTAT
on the target file and return proper error.
daemon/gvfsbackendsftp.c | 42 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 40 insertions(+), 2 deletions(-)
---
diff --git a/daemon/gvfsbackendsftp.c b/daemon/gvfsbackendsftp.c
index aae1690..51e2157 100644
--- a/daemon/gvfsbackendsftp.c
+++ b/daemon/gvfsbackendsftp.c
@@ -59,6 +59,7 @@
#include "gvfsjobqueryfsinfo.h"
#include "gvfsjobqueryattributes.h"
#include "gvfsjobenumerate.h"
+#include "gvfsjobmakedirectory.h"
#include "gvfsdaemonprotocol.h"
#include "gvfskeyring.h"
#include "sftp.h"
@@ -4344,6 +4345,27 @@ try_make_symlink (GVfsBackend *backend,
}
static void
+mkdir_stat_reply (GVfsBackendSftp *backend,
+ int reply_type,
+ GDataInputStream *reply,
+ guint32 len,
+ GVfsJob *job,
+ gpointer user_data)
+{
+ if (reply_type == SSH_FXP_STATUS)
+ /* We got some error, but lets report the original FAILURE, as
+ these extra errors are not really mkdir errors, we just wanted
+ to implement EEXISTS */
+ result_from_status_code (job, SSH_FX_FAILURE, -1, -1);
+ else if (reply_type != SSH_FXP_ATTRS)
+ g_vfs_job_failed (job, G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Invalid reply received"));
+ else
+ g_vfs_job_failed (job, G_IO_ERROR, G_IO_ERROR_EXISTS,
+ _("Target file exists"));
+}
+
+static void
make_directory_reply (GVfsBackendSftp *backend,
int reply_type,
GDataInputStream *reply,
@@ -4352,7 +4374,23 @@ make_directory_reply (GVfsBackendSftp *backend,
gpointer user_data)
{
if (reply_type == SSH_FXP_STATUS)
- result_from_status (job, reply, -1, -1);
+ {
+ gint stat_error;
+
+ stat_error = read_status_code (reply);
+ if (stat_error == SSH_FX_FAILURE)
+ {
+ /* Generic SFTP error, let's stat the target */
+ GDataOutputStream *command;
+
+ command = new_command_stream (backend,
+ SSH_FXP_LSTAT);
+ put_string (command, G_VFS_JOB_MAKE_DIRECTORY (job)->filename);
+ queue_command_stream_and_free (backend, command, mkdir_stat_reply, G_VFS_JOB (job), NULL);
+ }
+ else
+ result_from_status_code (job, stat_error, -1, -1);
+ }
else
g_vfs_job_failed (job, G_IO_ERROR, G_IO_ERROR_FAILED,
_("Invalid reply received"));
@@ -4371,7 +4409,7 @@ try_make_directory (GVfsBackend *backend,
put_string (command, filename);
/* No file info - flag 0 */
g_data_output_stream_put_uint32 (command, 0, NULL, NULL);
-
+
queue_command_stream_and_free (op_backend, command, make_directory_reply, G_VFS_JOB (job), NULL);
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]