[gvfs/wip/oholy/google-enumerate-volatile] google: Do not enumerate volatile entries if title matches id



commit 1e3a6141325dc6c9ff4ab3b365bd4f5f697b53e1
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Jul 12 10:35:47 2019 +0200

    google: Do not enumerate volatile entries if title matches id
    
    Currently, the volatile entry is enumerated if its title matches id
    of another entry. But we don't want to enumerate volatile entries
    to not confuse our clients. Let's add simple check to prevent this.

 daemon/gvfsbackendgoogle.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/daemon/gvfsbackendgoogle.c b/daemon/gvfsbackendgoogle.c
index e60ad510..31bf0f14 100644
--- a/daemon/gvfsbackendgoogle.c
+++ b/daemon/gvfsbackendgoogle.c
@@ -1499,23 +1499,38 @@ g_vfs_backend_google_enumerate (GVfsBackend           *_self,
   while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &entry))
     {
       DirEntriesKey *k;
+      GDataEntry *child;
+      gchar *child_id;
 
-      k = dir_entries_key_new (gdata_entry_get_id (entry), id);
-      if (g_hash_table_contains (self->dir_entries, k))
+      /* g_strdup() is necessary to prevent segfault because gdata_entry_get_id() calls g_free() */
+      child_id = g_strdup (gdata_entry_get_id (entry));
+
+      k = dir_entries_key_new (child_id, id);
+      if ((child = g_hash_table_lookup (self->dir_entries, k)) != NULL)
         {
           GFileInfo *info;
           gchar *entry_path;
           gchar *child_filename;
 
+          /* Be sure that we are not matching title of volatile file */
+          if (g_strcmp0 (child_id, gdata_entry_get_id (child)) != 0)
+            {
+              g_debug ("Skipping %s as it is volatile path for %s\n", child_id, gdata_entry_get_id (child));
+              g_free (child_id);
+              dir_entries_key_free (k);
+              continue;
+            }
+
           info = g_file_info_new ();
-          entry_path = g_build_path ("/", parent_path, gdata_entry_get_id (GDATA_ENTRY (entry)), NULL);
-          child_filename = g_build_filename (filename, gdata_entry_get_id (GDATA_ENTRY (entry)), NULL);
+          entry_path = g_build_path ("/", parent_path, child_id, NULL);
+          child_filename = g_build_filename (filename, child_id, NULL);
           build_file_info (self, entry, flags, info, matcher, child_filename, entry_path, NULL);
           g_vfs_job_enumerate_add_info (job, info);
           g_object_unref (info);
           g_free (entry_path);
         }
 
+      g_free (child_id);
       dir_entries_key_free (k);
     }
 


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