Subject: Re: bug#25414: [email-masked] does not build deterministically

From: Danny Milosavljevic <[email-masked]>
Date: Wed, 11 Jan 2017 00:33:15 +0100

On Wed, 11 Jan 2017 00:06:42 +0100
[email-masked] (Ludovic Courtès) wrote:

> Presumably ‘gdk-pixbuf-query-loaders’, which generates ‘loaders.cache’,
> does not sort the entries returned by readdir(2).

Yep.

gdk-pixbuf/queryloaders.c line 355 uses g_dir_open.

Docs: https://developer.gnome.org/glib/stable/glib-File-Utilities.html#g-dir-open "Note that the ordering is not defined."

One could use g_list_append to append it to a list and then g_list_sort and then g_list_free. Like below (untested! Seriously!):

--- gdk-pixbuf/queryloaders.c.orig      2017-01-11 00:17:32.865843062 +0100
+++ gdk-pixbuf/queryloaders.c   2017-01-11 00:31:29.428372177 +0100
@@ -354,16 +354,25 @@
 
                 dir = g_dir_open (path, 0, NULL);
                 if (dir) {
+                        GList *entries = NULL;
                         const char *dent;
 
                         while ((dent = g_dir_read_name (dir))) {
                                 gint len = strlen (dent);
                                 if (len > SOEXT_LEN &&
                                     strcmp (dent + len - SOEXT_LEN, SOEXT) == 0) {
-                                        query_module (contents, path, dent);
+                                        entries = g_list_append (entries, g_strdup (dent));
                                 }
                         }
                         g_dir_close (dir);
+                        entries = g_list_sort (entries, strcmp);
+                        GList *xentries;
+                        for (xentries = entries; xentries; xentries = g_list_next(xentries)) {
+                                dent = xentries->data;
+                                query_module (contents, path, dent);
+                                g_free (xentries->data);
+                        }
+                        g_list_free(entries);
                 }
 #else
                 g_string_append_printf (contents, "# dynamic loading of modules not supported\n");