static GHashTable *packages = NULL;
static GHashTable *locations = NULL;
+static GHashTable *path_positions = NULL;
static GHashTable *globals = NULL;
static GSList *search_dirs = NULL;
+static int scanned_dir_count = 0;
gboolean disable_uninstalled = FALSE;
}
debug_spew ("Scanning directory '%s'\n", dirname);
+
+ scanned_dir_count += 1;
while ((dent = readdir (dir)))
{
strcpy (filename + dirnamelen + 1, dent->d_name);
g_hash_table_insert (locations, pkgname, filename);
-
+ g_hash_table_insert (path_positions, pkgname,
+ GINT_TO_POINTER (scanned_dir_count));
+
debug_spew ("Will find package '%s' in file '%s'\n",
pkgname, filename);
}
packages = g_hash_table_new (g_str_hash, g_str_equal);
locations = g_hash_table_new (g_str_hash, g_str_equal);
+ path_positions = g_hash_table_new (g_str_hash, g_str_equal);
g_slist_foreach (search_dirs, (GFunc)scan_dir, NULL);
scan_dir (PKGLIBDIR);
return NULL;
}
+ pkg->path_position =
+ GPOINTER_TO_INT (g_hash_table_lookup (path_positions, pkg->name));
+
+ debug_spew ("Path position of '%s' is %d\n",
+ pkg->name, pkg->path_position);
+
if (strstr (location, "uninstalled.pc"))
pkg->uninstalled = TRUE;
return pkg->requires;
}
+static int
+pathposcmp (gconstpointer a, gconstpointer b)
+{
+ const Package *pa = a;
+ const Package *pb = b;
+
+ if (pa->path_position < pb->path_position)
+ return -1;
+ else if (pa->path_position > pb->path_position)
+ return 1;
+ else
+ return 0;
+}
+
+static GSList*
+packages_sort_by_path_position (GSList *list)
+{
+ return g_slist_sort (list, pathposcmp);
+}
+
static void
-recursive_fill_list (Package *pkg, GetListFunc func, GSList **listp)
+fill_one_level (Package *pkg, GetListFunc func, GSList **listp)
{
- GSList *tmp;
GSList *copy;
copy = g_slist_copy ((*func)(pkg));
*listp = g_slist_concat (*listp, copy);
+}
+
+static void
+recursive_fill_list (Package *pkg, GetListFunc func, GSList **listp)
+{
+ GSList *tmp;
+
+ fill_one_level (pkg, func, listp);
tmp = pkg->requires;
}
}
+static void
+fill_list_in_path_order_single_package (Package *pkg, GetListFunc func,
+ GSList **listp)
+{
+ /* First we get the list in natural/recursive order, then
+ * stable sort by path position
+ */
+ GSList *packages;
+ GSList *tmp;
+
+ packages = g_slist_append (packages, pkg);
+ recursive_fill_list (pkg, get_requires, &packages);
+
+ packages = packages_sort_by_path_position (packages);
+
+ tmp = packages;
+ while (tmp != NULL)
+ {
+ fill_one_level (tmp->data, func, listp);
+
+ tmp = tmp->next;
+ }
+
+ g_slist_free (packages);
+}
+
+static void
+fill_list_in_path_order (GSList *packages, GetListFunc func,
+ GSList **listp)
+{
+ GSList *tmp;
+ GSList *expanded;
+
+ expanded = NULL;
+ tmp = packages;
+ while (tmp != NULL)
+ {
+ expanded = g_slist_append (expanded, tmp->data);
+ recursive_fill_list (tmp->data, get_requires, &expanded);
+
+ tmp = tmp->next;
+ }
+
+ expanded = packages_sort_by_path_position (expanded);
+
+ tmp = expanded;
+ while (tmp != NULL)
+ {
+ fill_one_level (tmp->data, func, listp);
+
+ tmp = tmp->next;
+ }
+
+ g_slist_free (expanded);
+}
+
static gint
compare_req_version_names (gconstpointer a, gconstpointer b)
{
GSList *dups_list = NULL;
char *retval;
- recursive_fill_list (pkg, func, &dups_list);
+ fill_list_in_path_order_single_package (pkg, func, &dups_list);
list = string_list_strip_duplicates (dups_list);
GSList *dups_list = NULL;
char *retval;
- recursive_fill_list (pkg, func, &dups_list);
+ fill_list_in_path_order_single_package (pkg, func, &dups_list);
list = string_list_strip_duplicates_from_back (dups_list);
GSList *list;
char *retval;
- tmp = pkgs;
- while (tmp != NULL)
- {
- recursive_fill_list (tmp->data, func, &dups_list);
-
- tmp = g_slist_next (tmp);
- }
+ fill_list_in_path_order (pkgs, func, &dups_list);
list = string_list_strip_duplicates (dups_list);
GSList *list;
char *retval;
- tmp = pkgs;
- while (tmp != NULL)
- {
- recursive_fill_list (tmp->data, func, &dups_list);
-
- tmp = g_slist_next (tmp);
- }
+ fill_list_in_path_order (pkgs, func, &dups_list);
list = string_list_strip_duplicates_from_back (dups_list);
pkg->L_libs_merged = get_merged (pkg, get_L_libs);
return pkg->L_libs_merged;
-
}
char *