[gnome-builder] flatpak: register installations when creating service



commit 47c60a6962cd6be564090cf536e1b16f54122c6d
Author: Christian Hergert <chergert redhat com>
Date:   Fri Apr 30 15:29:48 2021 -0700

    flatpak: register installations when creating service
    
    We don't really need to send this information over from the UI process as
    the service process has access to all the same information.

 .../flatpak/daemon/ipc-flatpak-service-impl.c      | 55 ++++++++++++++++++----
 src/plugins/flatpak/gbp-flatpak-client.c           | 36 --------------
 2 files changed, 46 insertions(+), 45 deletions(-)
---
diff --git a/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c 
b/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
index 01f669219..c19564665 100644
--- a/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
+++ b/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
@@ -309,6 +309,31 @@ install_reload (IpcFlatpakServiceImpl *self,
     }
 }
 
+static gboolean
+add_installation (IpcFlatpakServiceImpl  *self,
+                  FlatpakInstallation    *installation,
+                  GError                **error)
+{
+  g_autoptr(GFile) file = NULL;
+  Install *install;
+
+  g_assert (IPC_IS_FLATPAK_SERVICE_IMPL (self));
+  g_assert (FLATPAK_IS_INSTALLATION (installation));
+
+  file = flatpak_installation_get_path (installation);
+
+  if (!(install = install_new (self, installation, error)))
+    return FALSE;
+
+  install_reload (self, install);
+
+  g_hash_table_insert (self->installs,
+                       g_steal_pointer (&file),
+                       g_steal_pointer (&install));
+
+  return TRUE;
+}
+
 static gboolean
 ipc_flatpak_service_impl_add_installation (IpcFlatpakService     *service,
                                            GDBusMethodInvocation *invocation,
@@ -328,17 +353,9 @@ ipc_flatpak_service_impl_add_installation (IpcFlatpakService     *service,
 
   if (!g_hash_table_contains (self->installs, file))
     {
-      Install *install;
-
       if (!(installation = flatpak_installation_new_for_path (file, is_user, NULL, &error)) ||
-          !(install = install_new (self, installation, &error)))
+          !add_installation (self, installation, &error))
         return complete_wrapped_error (invocation, error);
-
-      install_reload (self, install);
-
-      g_hash_table_insert (self->installs,
-                           g_steal_pointer (&file),
-                           g_steal_pointer (&install));
     }
 
   ipc_flatpak_service_complete_add_installation (service, invocation);
@@ -824,6 +841,25 @@ service_iface_init (IpcFlatpakServiceIface *iface)
 G_DEFINE_TYPE_WITH_CODE (IpcFlatpakServiceImpl, ipc_flatpak_service_impl, IPC_TYPE_FLATPAK_SERVICE_SKELETON,
                          G_IMPLEMENT_INTERFACE (IPC_TYPE_FLATPAK_SERVICE, service_iface_init))
 
+static void
+ipc_flatpak_service_impl_constructed (GObject *object)
+{
+  IpcFlatpakServiceImpl *self = (IpcFlatpakServiceImpl *)object;
+  g_autoptr(GPtrArray) installations = NULL;
+  g_autoptr(FlatpakInstallation) user = NULL;
+
+  G_OBJECT_CLASS (ipc_flatpak_service_impl_parent_class)->constructed (object);
+
+  if ((user = flatpak_installation_new_user (NULL, NULL)))
+    add_installation (self, user, NULL);
+
+  if ((installations = flatpak_get_system_installations (NULL, NULL)))
+    {
+      for (guint i = 0; i < installations->len; i++)
+        add_installation (self, g_ptr_array_index (installations, i), NULL);
+    }
+}
+
 static void
 ipc_flatpak_service_impl_finalize (GObject *object)
 {
@@ -840,6 +876,7 @@ ipc_flatpak_service_impl_class_init (IpcFlatpakServiceImplClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->constructed = ipc_flatpak_service_impl_constructed;
   object_class->finalize = ipc_flatpak_service_impl_finalize;
 }
 
diff --git a/src/plugins/flatpak/gbp-flatpak-client.c b/src/plugins/flatpak/gbp-flatpak-client.c
index b9ed620da..fb5e155c3 100644
--- a/src/plugins/flatpak/gbp-flatpak-client.c
+++ b/src/plugins/flatpak/gbp-flatpak-client.c
@@ -49,40 +49,6 @@ enum {
 
 G_DEFINE_TYPE (GbpFlatpakClient, gbp_flatpak_client, IDE_TYPE_OBJECT)
 
-static void
-gbp_flatpak_client_register_installations (GbpFlatpakClient  *self,
-                                           IpcFlatpakService *service)
-{
-  g_autofree char *user_path = NULL;
-  g_autofree char *system_path = NULL;
-
-  g_assert (GBP_IS_FLATPAK_CLIENT (self));
-  g_assert (IPC_IS_FLATPAK_SERVICE (service));
-
-  /*
-   * First we want to load the user installation so that it is at index 0.
-   * This naturally prefers the user installation for various operations
-   * which is precisely what we want.
-   *
-   * We can't use flatpak_installation_new_user() since that will not map to
-   * the user's real flatpak user installation. It will instead map to the
-   * reidrected XDG_DATA_DIRS version. Therefore, we synthesize the path to the
-   * location we know it should be at.
-   */
-  user_path = g_build_filename (g_get_home_dir (), ".local", "share", "flatpak", NULL);
-  ipc_flatpak_service_call_add_installation (service, user_path, TRUE, NULL, NULL, NULL);
-
-  /* We can't really access any of the system installations other than the
-   * one we know about (as flatpak_get_system_installations() never really
-   * worked correctly within the Flatpak environment.
-   *
-   * We could try to fix this for distro shipped versions, but they can deal
-   * with the fallout there because we only support Flatpak upstream and the
-   * distros we work on ourselves are all going Flatpak for apps.
-   */
-  ipc_flatpak_service_call_add_installation (service, "/var/lib/flatpak", FALSE, NULL, NULL, NULL);
-}
-
 static void
 gbp_flatpak_client_subprocess_spawned (GbpFlatpakClient        *self,
                                        IdeSubprocess           *subprocess,
@@ -142,8 +108,6 @@ gbp_flatpak_client_subprocess_spawned (GbpFlatpakClient        *self,
   self->get_service.tail = NULL;
   self->get_service.length = 0;
 
-  gbp_flatpak_client_register_installations (self, self->service);
-
   for (const GList *iter = queued; iter != NULL; iter = iter->next)
     {
       IdeTask *task = iter->data;


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