updateiconcache: sort directory entries before scanning

Based on the openSUSE gtk2-updateiconcache_sort.patch.

Sort directory entries while building the icon cache so cache output is deterministic, but keep the implementation portable by using GLib arrays instead of scandir()/alphasort(). Also free the scanned directory path before returning.
This commit is contained in:
Daemonratte 2026-05-14 15:00:25 +02:00
commit c062dcb54d

View file

@ -608,6 +608,16 @@ replace_backslashes_with_slashes (gchar *path)
path[i] = '/';
}
static gint
compare_string_pointers (gconstpointer a,
gconstpointer b)
{
const gchar * const *str_a = a;
const gchar * const *str_b = b;
return strcmp (*str_a, *str_b);
}
static GList *
scan_directory (const gchar *base_path,
const gchar *subdir,
@ -617,10 +627,12 @@ scan_directory (const gchar *base_path,
{
GHashTable *dir_hash;
GDir *dir;
GPtrArray *names;
const gchar *name;
gchar *dir_path;
gboolean dir_added = FALSE;
guint dir_index = 0xffff;
guint i;
dir_path = g_build_path ("/", base_path, subdir, NULL);
@ -628,12 +640,25 @@ scan_directory (const gchar *base_path,
dir = g_dir_open (dir_path, 0, NULL);
if (!dir)
return directories;
{
g_free (dir_path);
return directories;
}
names = g_ptr_array_new_with_free_func (g_free);
while ((name = g_dir_read_name (dir)))
g_ptr_array_add (names, g_strdup (name));
g_dir_close (dir);
g_ptr_array_sort (names, compare_string_pointers);
dir_hash = g_hash_table_new (g_str_hash, g_str_equal);
while ((name = g_dir_read_name (dir)))
for (i = 0; i < names->len; i++)
{
name = g_ptr_array_index (names, i);
gchar *path;
gboolean retval;
int flags = 0;
@ -712,7 +737,8 @@ scan_directory (const gchar *base_path,
g_free (path);
}
g_dir_close (dir);
g_ptr_array_free (names, TRUE);
g_free (dir_path);
/* Move dir into the big file hash */
g_hash_table_foreach_remove (dir_hash, foreach_remove_func, files);