summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMayank Sharma <mayank8019@gmail.com>2019-07-09 14:55:10 +0530
committerMayank Sharma <mayank8019@gmail.com>2019-07-09 16:20:27 +0530
commit212f531ee73686cde7f1cbf93e45f961845ac5eb (patch)
treead7aa3eb126fd115793381e41e94d5a243849165
parent83b1c44f03680ec000f4e557ea19c9102ad88513 (diff)
downloadgvfs-212f531ee73686cde7f1cbf93e45f961845ac5eb.tar.gz
google: Check ownership in is_owner() without additional HTTP request
Earlier, we were fetching ACL feed of an entry and then checking the ownership by comparing account identity with elements from this feed. This was slow due to Network IO being performed while checking ownership. We now use GDataAuthors on a GDataEntry to get the list of "owners" of the file. We then use the GoaObject stored on GDataGoaAuthorizer to get the account which is being used by GDataService. Finally, we take the email address of account and compare them to check the ownership. This method now runs without anymore additional network requests.
-rw-r--r--daemon/gvfsbackendgoogle.c60
1 files changed, 14 insertions, 46 deletions
diff --git a/daemon/gvfsbackendgoogle.c b/daemon/gvfsbackendgoogle.c
index e60ad510..35cea1dd 100644
--- a/daemon/gvfsbackendgoogle.c
+++ b/daemon/gvfsbackendgoogle.c
@@ -357,50 +357,27 @@ get_parent_ids (GVfsBackendGoogle *self,
/* ---------------------------------------------------------------------------------------------------- */
static gboolean
-is_owner (GVfsBackendGoogle *self,
- GDataEntry *entry,
- GCancellable *cancellable,
- GError **error)
+is_owner (GVfsBackendGoogle *self, GDataEntry *entry)
{
- GDataFeed *acl_feed;
- GDataAccessRule *rule;
GList *l;
- GError *local_error = NULL;
- gboolean ret_val = FALSE;
-
- acl_feed = gdata_access_handler_get_rules (GDATA_ACCESS_HANDLER (GDATA_DOCUMENTS_ENTRY (entry)),
- GDATA_SERVICE (self->service),
- cancellable,
- NULL,
- NULL,
- &local_error);
-
- if (local_error != NULL)
- {
- sanitize_error (&local_error);
- g_propagate_error (error, local_error);
+ GDataGoaAuthorizer *goa_authorizer;
+ GoaAccount *account;
+ const gchar *account_identity;
- goto out;
- }
+ goa_authorizer = GDATA_GOA_AUTHORIZER (gdata_service_get_authorizer (GDATA_SERVICE (self->service)));
+ account = goa_object_peek_account (gdata_goa_authorizer_get_goa_object (goa_authorizer));
+ account_identity = goa_account_get_identity (account);
- for (l = gdata_feed_get_entries (acl_feed); l != NULL; l = l->next)
+ for (l = gdata_entry_get_authors (entry); l != NULL; l = l->next)
{
- const gchar *scope_value, *scope_type, *role;
- rule = GDATA_ACCESS_RULE (l->data);
- role = gdata_access_rule_get_role (rule);
- gdata_access_rule_get_scope (rule, &scope_type, &scope_value);
+ GDataAuthor *author = GDATA_AUTHOR (l->data);
- if (g_strcmp0 (scope_value, self->account_identity) == 0 &&
- g_strcmp0 (role, GDATA_DOCUMENTS_ACCESS_ROLE_OWNER) == 0)
- {
- ret_val = TRUE;
- goto out;
- }
+ if (g_strcmp0 (gdata_author_get_email_address (author), account_identity) == 0) {
+ return TRUE;
+ }
}
- out:
- g_clear_object (&acl_feed);
- return ret_val;
+ return FALSE;
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -1353,7 +1330,6 @@ g_vfs_backend_google_delete (GVfsBackend *_self,
GError *error;
gchar *entry_path = NULL;
GList *parent_ids;
- gboolean owner = FALSE;
guint parent_ids_len;
g_rec_mutex_lock (&self->mutex);
@@ -1390,17 +1366,9 @@ g_vfs_backend_google_delete (GVfsBackend *_self,
error = NULL;
- owner = is_owner (self, GDATA_ENTRY (entry), cancellable, &error);
- if (error != NULL)
- {
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
- g_error_free (error);
- goto out;
- }
-
parent_ids = get_parent_ids (self, entry);
parent_ids_len = g_list_length (parent_ids);
- if (parent_ids_len > 1 || !owner)
+ if (parent_ids_len > 1 || !is_owner (self, GDATA_ENTRY (entry)))
{
/* gdata_documents_service_remove_entry_from_folder () returns the
* updated entry variable provided as argument with an increased ref.