[gnome-builder] flatpak: Delete our remote on application startup



commit de3bb5b1c165bd6cd1585eb947c9913895ccbca4
Author: Matthew Leeds <mleeds redhat com>
Date:   Thu Nov 17 18:49:42 2016 -0600

    flatpak: Delete our remote on application startup
    
    Since the user cache dir is different on the host OS than from within a
    flatpak (~/.cache/gnome-builder/... vs ~/.var/app/org.gnome.Builder/...),
    the flatpak runtime ends up trying to create a remote with the same name
    as an existing one (if Builder has been run outside a flatpak) and a
    different location, which fails, eventually causing the Run button not
    to work. This commit fixes the issue by deleting the remote we create
    upon application startup.

 plugins/flatpak/Makefile.am                     |    2 +
 plugins/flatpak/gbp-flatpak-application-addin.c |   76 +++++++++++++++++++++++
 plugins/flatpak/gbp-flatpak-application-addin.h |   32 ++++++++++
 plugins/flatpak/gbp-flatpak-plugin.c            |    4 +
 plugins/flatpak/gbp-flatpak-runtime.c           |    2 +-
 plugins/flatpak/gbp-flatpak-runtime.h           |    2 +
 6 files changed, 117 insertions(+), 1 deletions(-)
---
diff --git a/plugins/flatpak/Makefile.am b/plugins/flatpak/Makefile.am
index 147f210..3f31772 100644
--- a/plugins/flatpak/Makefile.am
+++ b/plugins/flatpak/Makefile.am
@@ -19,6 +19,8 @@ libflatpak_plugin_la_SOURCES = \
        gbp-flatpak-plugin.c \
        gbp-flatpak-runner.c \
        gbp-flatpak-runner.h \
+       gbp-flatpak-application-addin.c \
+       gbp-flatpak-application-addin.h \
        $(NULL)
 
 libflatpak_plugin_la_CFLAGS = $(PLUGIN_CFLAGS) $(FLATPAK_CFLAGS)
diff --git a/plugins/flatpak/gbp-flatpak-application-addin.c b/plugins/flatpak/gbp-flatpak-application-addin.c
new file mode 100644
index 0000000..83994bb
--- /dev/null
+++ b/plugins/flatpak/gbp-flatpak-application-addin.c
@@ -0,0 +1,76 @@
+/* gbp-flatpak-application-addin.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gbp-flatpak-application-addin.h"
+#include "gbp-flatpak-runtime.h"
+
+struct _GbpFlatpakApplicationAddin
+{
+  GObject parent_instance;
+};
+
+static void application_addin_iface_init (IdeApplicationAddinInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (GbpFlatpakApplicationAddin,
+                        gbp_flatpak_application_addin,
+                        G_TYPE_OBJECT,
+                        0,
+                        G_IMPLEMENT_INTERFACE (IDE_TYPE_APPLICATION_ADDIN, application_addin_iface_init))
+
+static void
+gbp_flatpak_application_addin_load (IdeApplicationAddin *addin,
+                                    IdeApplication      *application)
+{
+  g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+  g_autoptr(IdeSubprocess) process = NULL;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (GBP_IS_FLATPAK_APPLICATION_ADDIN (addin));
+  g_assert (IDE_IS_APPLICATION (application));
+
+  launcher = ide_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE | 
G_SUBPROCESS_FLAGS_STDERR_SILENCE);
+  ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
+  ide_subprocess_launcher_push_argv (launcher, "flatpak");
+  ide_subprocess_launcher_push_argv (launcher, "remote-delete");
+  ide_subprocess_launcher_push_argv (launcher, "--user");
+  ide_subprocess_launcher_push_argv (launcher, "--force");
+  ide_subprocess_launcher_push_argv (launcher, FLATPAK_REPO_NAME);
+  process = ide_subprocess_launcher_spawn (launcher, NULL, &error);
+  if (process == NULL)
+    {
+      g_warning ("%s", error->message);
+      return;
+    }
+  ide_subprocess_wait (process, NULL, NULL);
+}
+
+static void
+gbp_flatpak_application_addin_class_init (GbpFlatpakApplicationAddinClass *klass)
+{
+}
+
+static void
+gbp_flatpak_application_addin_init (GbpFlatpakApplicationAddin *self)
+{
+}
+
+static void
+application_addin_iface_init (IdeApplicationAddinInterface *iface)
+{
+  iface->load = gbp_flatpak_application_addin_load;
+}
diff --git a/plugins/flatpak/gbp-flatpak-application-addin.h b/plugins/flatpak/gbp-flatpak-application-addin.h
new file mode 100644
index 0000000..31de47d
--- /dev/null
+++ b/plugins/flatpak/gbp-flatpak-application-addin.h
@@ -0,0 +1,32 @@
+/* gbp-flatpak-application-addin.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GBP_FLATPAK_APPLICATION_ADDIN_H
+#define GBP_FLATPAK_APPLICATION_ADDIN_H
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_FLATPAK_APPLICATION_ADDIN (gbp_flatpak_application_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakApplicationAddin, gbp_flatpak_application_addin, GBP, 
FLATPAK_APPLICATION_ADDIN, GObject)
+
+G_END_DECLS
+
+#endif /* GBP_FLATPAK_APPLICATION_ADDIN_H */
diff --git a/plugins/flatpak/gbp-flatpak-plugin.c b/plugins/flatpak/gbp-flatpak-plugin.c
index d0815d8..2ea41ab 100644
--- a/plugins/flatpak/gbp-flatpak-plugin.c
+++ b/plugins/flatpak/gbp-flatpak-plugin.c
@@ -20,6 +20,7 @@
 #include <ide.h>
 
 #include "gbp-flatpak-runtime-provider.h"
+#include "gbp-flatpak-application-addin.h"
 
 void
 peas_register_types (PeasObjectModule *module)
@@ -27,4 +28,7 @@ peas_register_types (PeasObjectModule *module)
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_RUNTIME_PROVIDER,
                                               GBP_TYPE_FLATPAK_RUNTIME_PROVIDER);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_APPLICATION_ADDIN,
+                                              GBP_TYPE_FLATPAK_APPLICATION_ADDIN);
 }
diff --git a/plugins/flatpak/gbp-flatpak-runtime.c b/plugins/flatpak/gbp-flatpak-runtime.c
index 656f0f3..fe02270 100644
--- a/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/plugins/flatpak/gbp-flatpak-runtime.c
@@ -738,7 +738,7 @@ gbp_flatpak_runtime_prepare_configuration (IdeRuntime       *runtime,
   if (!ide_str_empty0 (self->app_id))
     ide_configuration_set_app_id (configuration, self->app_id);
   ide_configuration_set_prefix (configuration, "/app");
-  ide_configuration_set_internal_string (configuration, "flatpak-repo-name", "gnome-builder-builds");
+  ide_configuration_set_internal_string (configuration, "flatpak-repo-name", FLATPAK_REPO_NAME);
 }
 
 static void
diff --git a/plugins/flatpak/gbp-flatpak-runtime.h b/plugins/flatpak/gbp-flatpak-runtime.h
index feecd97..3579994 100644
--- a/plugins/flatpak/gbp-flatpak-runtime.h
+++ b/plugins/flatpak/gbp-flatpak-runtime.h
@@ -27,6 +27,8 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbpFlatpakRuntime, gbp_flatpak_runtime, GBP, FLATPAK_RUNTIME, IdeRuntime)
 
+#define FLATPAK_REPO_NAME "gnome-builder-builds"
+
 G_END_DECLS
 
 #endif /* GBP_FLATPAK_RUNTIME_H */


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