static gint compare_node(mega_node* a, mega_node* b) { gchar path1[4096]; gchar path2[4096]; if (mega_node_get_path(a, path1, 4096) && mega_node_get_path(b, path2, 4096)) return strcmp(path1, path2); return 0; }
static void build_pathmap(MegaFilesystem* filesystem, GList** nodes, MegaNode* parent, const gchar* base_path) { MegaFilesystemPrivate* priv = filesystem->priv; GList *i, *next, *matched = NULL; if (parent) mega_node_remove_children(parent); for (i = *nodes; i; i = next) { MegaNode* node = i->data; next = i->next; if (mega_node_is_child(node, parent)) { gchar* path = g_strdup_printf("%s/%s", base_path, mega_node_get_name(node)); // handle dups if (g_hash_table_lookup(priv->pathmap, path)) { gchar* tmp = g_strconcat(path, ".", mega_node_get_handle(node), NULL); g_free(path); path = tmp; } if (parent) mega_node_add_child(parent, node); g_object_set(node, "path", path, "parent", parent, NULL); g_hash_table_insert(priv->pathmap, g_strdup(path), g_object_ref(node)); *nodes = g_list_remove_link(*nodes, i); matched = g_list_concat(matched, i); g_free(path); } // first iteration if (parent == NULL && mega_node_get_handle(node)) { g_hash_table_insert(priv->handlemap, g_strdup(mega_node_get_handle(node)), g_object_ref(node)); if (mega_node_is_child(node, NULL)) priv->root_nodes = g_slist_prepend(priv->root_nodes, g_object_ref(node)); } } for (i = matched; i; i = i->next) build_pathmap(filesystem, nodes, i->data, mega_node_get_path(i->data)); g_list_free(matched); }