diff options
author | Ondrej Holy <oholy@redhat.com> | 2018-02-08 17:32:47 +0100 |
---|---|---|
committer | Ondrej Holy <oholy@redhat.com> | 2018-02-08 17:32:47 +0100 |
commit | 7291c6b5efa87e8b1edadab31122f1fe7def3a78 (patch) | |
tree | 0c6eb2df6b48ecec8afc8df2b5b7d2a510f76263 | |
parent | cb51e7e161f1ec80c7ec728d7d8db41226a66543 (diff) | |
download | gvfs-7291c6b5efa87e8b1edadab31122f1fe7def3a78.tar.gz |
google: Return error when trying to replace native files
Currently, replacing of google native files silently fails without
any error, which may possibly lead to data loss. Let's return an error
in this case.
-rw-r--r-- | daemon/gvfsbackendgoogle.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/daemon/gvfsbackendgoogle.c b/daemon/gvfsbackendgoogle.c index 6aa7e7c0..ca919a5f 100644 --- a/daemon/gvfsbackendgoogle.c +++ b/daemon/gvfsbackendgoogle.c @@ -868,6 +868,21 @@ generate_copy_name (GVfsBackendGoogle *self, GDataEntry *entry) /* ---------------------------------------------------------------------------------------------------- */ +static gboolean +is_native_file (GDataEntry *entry) +{ + gchar *content_type; + gboolean ret = FALSE; + + content_type = get_content_type_from_entry (entry); + if (content_type != NULL && g_str_has_prefix (content_type, CONTENT_TYPE_PREFIX_GOOGLE)) + ret = TRUE; + + g_free (content_type); + + return ret; +} + static void build_file_info (GVfsBackendGoogle *self, GDataEntry *entry, @@ -930,7 +945,7 @@ build_file_info (GVfsBackendGoogle *self, file_type = G_FILE_TYPE_REGULAR; /* We want native Drive content to open in the browser. */ - if (content_type != NULL && g_str_has_prefix (content_type, CONTENT_TYPE_PREFIX_GOOGLE)) + if (is_native_file (entry)) { GDataLink *alternate; const gchar *uri; @@ -1819,6 +1834,14 @@ g_vfs_backend_google_push (GVfsBackend *_self, goto out; } } + else if (is_native_file (existing_entry)) + { + g_vfs_job_failed (G_VFS_JOB (job), + G_IO_ERROR, + G_IO_ERROR_NOT_REGULAR_FILE, + _("Target file is not a regular file")); + goto out; + } else { if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) @@ -2649,7 +2672,7 @@ g_vfs_backend_google_replace (GVfsBackend *_self, g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY, _("Target file is a directory")); goto out; } - else if (!GDATA_IS_DOCUMENTS_DOCUMENT (existing_entry)) + else if (is_native_file (existing_entry)) { g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, |