[libpeas] engine: improve reproducibility of resource-based plugins



commit a2bc201b853d717fe1d8484872c47685571112e6
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 18 13:51:45 2022 -0700

    engine: improve reproducibility of resource-based plugins
    
    We don't have guarantees that the children will be in a predictable order,
    which can be annoying for tracking down issues users have that the
    developer cannot reproduce. This just normalizes things so that we can be
    more sure that the issues will be predictable.

 libpeas/peas-engine.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index 9929f69..b6eee05 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -23,6 +23,7 @@
 
 #include "config.h"
 
+#include <stdlib.h>
 #include <string.h>
 
 #include "peas-i18n-priv.h"
@@ -241,6 +242,16 @@ load_file_dir_real (PeasEngine  *engine,
   return found;
 }
 
+static int
+strptrcmp (gconstpointer a,
+           gconstpointer b)
+{
+  const char * const *stra = a;
+  const char * const *strb = b;
+
+  return strcmp (*stra, *strb);
+}
+
 static gboolean
 load_resource_dir_real (PeasEngine  *engine,
                         const gchar *module_dir,
@@ -267,6 +278,9 @@ load_resource_dir_real (PeasEngine  *engine,
       return FALSE;
     }
 
+  /* Always sort resource children for improved reproducibility */
+  qsort (children, g_strv_length (children), sizeof (char *), strptrcmp);
+
   for (i = 0; children[i] != NULL; ++i)
     {
       gboolean is_dir;


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