[gvfs/wip/rishi/goa: 4/4] google: Fix error handling
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/wip/rishi/goa: 4/4] google: Fix error handling
- Date: Wed, 2 Sep 2015 11:42:38 +0000 (UTC)
commit 613daacd40a5592b9ba1f130678ba7e43a43bc1c
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Sep 2 13:41:04 2015 +0200
google: Fix error handling
daemon/gvfsbackendgoogle.c | 157 +++++++++++++++++++++++++------------------
1 files changed, 91 insertions(+), 66 deletions(-)
---
diff --git a/daemon/gvfsbackendgoogle.c b/daemon/gvfsbackendgoogle.c
index a2ffd60..243e4ab 100644
--- a/daemon/gvfsbackendgoogle.c
+++ b/daemon/gvfsbackendgoogle.c
@@ -928,6 +928,7 @@ g_vfs_backend_google_copy (GVfsBackend *_self,
GError *error;
GType source_entry_type;
gboolean needs_rebuild = FALSE;
+ gboolean destination_not_directory = FALSE;
const gchar *etag;
const gchar *id;
const gchar *summary;
@@ -943,13 +944,7 @@ g_vfs_backend_google_copy (GVfsBackend *_self,
* G_IO_ERROR_CANT_CREATE_BACKUP to proceed with the GIO
* fallback copy.
*/
- g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Operation not
supported");
- goto out;
- }
-
- if (flags & G_FILE_COPY_OVERWRITE)
- {
- g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Operation not
supported");
+ g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Operation
unsupported"));
goto out;
}
@@ -962,16 +957,11 @@ g_vfs_backend_google_copy (GVfsBackend *_self,
if (error != NULL)
{
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY))
- {
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
- g_error_free (error);
- goto out;
- }
+ destination_not_directory = TRUE;
else
- {
- g_error_free (error);
- needs_rebuild = TRUE;
- }
+ needs_rebuild = TRUE;
+
+ g_error_free (error);
}
if (needs_rebuild)
@@ -994,40 +984,39 @@ g_vfs_backend_google_copy (GVfsBackend *_self,
goto out;
}
- g_free (destination_basename);
-
- error = NULL;
- destination_parent = resolve_dir (self, destination, &destination_basename, &error);
- if (error != NULL)
+ if (!destination_not_directory)
{
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
- g_error_free (error);
- goto out;
+ g_free (destination_basename);
+
+ error = NULL;
+ destination_parent = resolve_dir (self, destination, &destination_basename, &error);
+ if (error != NULL)
+ {
+ g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ g_error_free (error);
+ goto out;
+ }
}
}
- if (GDATA_IS_DOCUMENTS_FOLDER (source_entry))
+ if (destination_not_directory)
{
- g_vfs_job_failed (G_VFS_JOB (job),
- G_IO_ERROR,
- G_IO_ERROR_WOULD_RECURSE,
- _("Can't recursively copy directory"));
+ g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY, _("The file is not a
directory"));
goto out;
}
- /* At this point, the source can never be a directory. So we can
- * ignore the issue of copying a directory over another
- * (ie. G_IO_ERROR_WOULD_MERGE).
- */
existing_entry = resolve_child (self, destination_parent, destination_basename);
if (existing_entry != NULL)
{
- if (GDATA_IS_DOCUMENTS_FOLDER (existing_entry))
+ if (flags & G_FILE_COPY_OVERWRITE)
{
- g_vfs_job_failed (G_VFS_JOB (job),
- G_IO_ERROR,
- G_IO_ERROR_IS_DIRECTORY,
- _("Can't copy file over directory"));
+ /* We don't support overwrites, so we don't need to care
+ * about G_IO_ERROR_IS_DIRECTORY and G_IO_ERROR_WOULD_MERGE.
+ */
+ g_vfs_job_failed_literal (G_VFS_JOB (job),
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation unsupported"));
goto out;
}
else
@@ -1036,6 +1025,17 @@ g_vfs_backend_google_copy (GVfsBackend *_self,
goto out;
}
}
+ else
+ {
+ if (GDATA_IS_DOCUMENTS_FOLDER (source_entry))
+ {
+ g_vfs_job_failed (G_VFS_JOB (job),
+ G_IO_ERROR,
+ G_IO_ERROR_WOULD_RECURSE,
+ _("Can't recursively copy directory"));
+ goto out;
+ }
+ }
etag = gdata_entry_get_etag (source_entry);
id = gdata_entry_get_id (source_entry);
@@ -1101,7 +1101,7 @@ g_vfs_backend_google_create_dir_monitor (GVfsBackend *_self,
if (flags & G_FILE_MONITOR_SEND_MOVED)
{
- g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Operation not
supported");
+ g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Operation
unsupported"));
goto out;
}
@@ -1566,7 +1566,7 @@ g_vfs_backend_google_push (GVfsBackend *_self,
* G_IO_ERROR_CANT_CREATE_BACKUP to proceed with the GIO
* fallback copy.
*/
- g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Operation not
supported");
+ g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Operation
unsupported"));
goto out;
}
@@ -1587,15 +1587,6 @@ g_vfs_backend_google_push (GVfsBackend *_self,
goto out;
}
- if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
- {
- g_vfs_job_failed (G_VFS_JOB (job),
- G_IO_ERROR,
- G_IO_ERROR_WOULD_RECURSE,
- _("Can't recursively copy directory"));
- goto out;
- }
-
error = NULL;
destination_parent = resolve_dir_and_rebuild (self, destination, cancellable, &destination_basename,
&error);
if (error != NULL)
@@ -1605,10 +1596,6 @@ g_vfs_backend_google_push (GVfsBackend *_self,
goto out;
}
- /* At this point, the source can never be a directory. So we can
- * ignore the issue of copying a directory over another
- * (ie. G_IO_ERROR_WOULD_MERGE).
- */
existing_entry = resolve_child (self, destination_parent, destination_basename);
if (existing_entry != NULL)
{
@@ -1616,11 +1603,33 @@ g_vfs_backend_google_push (GVfsBackend *_self,
{
if (GDATA_IS_DOCUMENTS_FOLDER (existing_entry))
{
- g_vfs_job_failed (G_VFS_JOB (job),
- G_IO_ERROR,
- G_IO_ERROR_IS_DIRECTORY,
- _("Can't copy file over directory"));
- goto out;
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ g_vfs_job_failed (G_VFS_JOB (job),
+ G_IO_ERROR,
+ G_IO_ERROR_WOULD_MERGE,
+ _("Can't copy directory over directory"));
+ goto out;
+ }
+ else
+ {
+ g_vfs_job_failed (G_VFS_JOB (job),
+ G_IO_ERROR,
+ G_IO_ERROR_IS_DIRECTORY,
+ _("Can't copy file over directory"));
+ goto out;
+ }
+ }
+ else
+ {
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ g_vfs_job_failed (G_VFS_JOB (job),
+ G_IO_ERROR,
+ G_IO_ERROR_WOULD_RECURSE,
+ _("Can't recursively copy directory"));
+ goto out;
+ }
}
needs_overwrite = TRUE;
@@ -1631,6 +1640,17 @@ g_vfs_backend_google_push (GVfsBackend *_self,
goto out;
}
}
+ else
+ {
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ g_vfs_job_failed (G_VFS_JOB (job),
+ G_IO_ERROR,
+ G_IO_ERROR_WOULD_RECURSE,
+ _("Can't recursively copy directory"));
+ goto out;
+ }
+ }
g_debug (" will overwrite: %d\n", needs_overwrite);
@@ -2224,12 +2244,6 @@ g_vfs_backend_google_create (GVfsBackend *_self,
g_rec_mutex_lock (&self->mutex);
g_debug ("+ create: %s, %d\n", filename, flags);
- if (flags & G_FILE_CREATE_REPLACE_DESTINATION)
- {
- g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Operation not
supported");
- goto out;
- }
-
if (g_strcmp0 (filename, "/") == 0)
{
g_vfs_job_failed (G_VFS_JOB (job),
@@ -2254,8 +2268,19 @@ g_vfs_backend_google_create (GVfsBackend *_self,
existing_entry = resolve_child (self, parent, basename);
if (existing_entry != NULL)
{
- g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_EXISTS, _("Target file already exists"));
- goto out;
+ if (flags & G_FILE_CREATE_REPLACE_DESTINATION)
+ {
+ g_vfs_job_failed_literal (G_VFS_JOB (job),
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ _("Operation unsupported"));
+ goto out;
+ }
+ else
+ {
+ g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_EXISTS, _("Target file already exists"));
+ goto out;
+ }
}
document = gdata_documents_document_new (NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]