[gnome-builder] podman: deduplicate podman runtimes



commit dfaf94dceacb9c5180c9f8e6d288d9740f397999
Author: Christian Hergert <chergert redhat com>
Date:   Sun Feb 28 16:54:22 2021 -0800

    podman: deduplicate podman runtimes
    
    We might have already seen some runtimes with previous loading, so ignore
    the new runtime if we already have one matching the ID.
    
    Fixes #1407

 src/plugins/podman/gbp-podman-runtime-provider.c | 31 ++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/podman/gbp-podman-runtime-provider.c 
b/src/plugins/podman/gbp-podman-runtime-provider.c
index 61f9b494a..782064343 100644
--- a/src/plugins/podman/gbp-podman-runtime-provider.c
+++ b/src/plugins/podman/gbp-podman-runtime-provider.c
@@ -38,6 +38,30 @@ struct _GbpPodmanRuntimeProvider
   const gchar       *runtime_id;
 };
 
+static gboolean
+contains_runtime (GbpPodmanRuntimeProvider *self,
+                  GbpPodmanRuntime         *runtime)
+{
+  const char *id;
+  guint n_items;
+
+  g_assert (GBP_IS_PODMAN_RUNTIME_PROVIDER (self));
+  g_assert (GBP_IS_PODMAN_RUNTIME (runtime));
+
+  id = ide_runtime_get_id (IDE_RUNTIME (runtime));
+  n_items = ide_object_get_n_children (IDE_OBJECT (self));
+
+  for (guint i = 0; i < n_items; i++)
+    {
+      IdeObject *ele = ide_object_get_nth_child (IDE_OBJECT (self), i);
+
+      if (g_strcmp0 (id, ide_runtime_get_id (IDE_RUNTIME (ele))) == 0)
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 gbp_podman_runtime_provider_apply_cb (JsonArray *ar,
                                       guint      index_,
@@ -62,8 +86,11 @@ gbp_podman_runtime_provider_apply_cb (JsonArray *ar,
 
   if ((runtime = gbp_podman_runtime_new (obj)))
     {
-      ide_object_append (IDE_OBJECT (self), IDE_OBJECT (runtime));
-      ide_runtime_manager_add (self->manager, IDE_RUNTIME (runtime));
+      if (!contains_runtime (self, runtime))
+        {
+          ide_object_append (IDE_OBJECT (self), IDE_OBJECT (runtime));
+          ide_runtime_manager_add (self->manager, IDE_RUNTIME (runtime));
+        }
     }
 
   IDE_EXIT;


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