[gnome-builder/gnome-builder-41] flatpak: allow setting data-dir for private repo
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/gnome-builder-41] flatpak: allow setting data-dir for private repo
- Date: Fri, 19 Nov 2021 05:50:14 +0000 (UTC)
commit 80639aa72b2feaac09430cf334292f31400e3724
Author: Christian Hergert <chergert redhat com>
Date: Thu Nov 18 20:06:24 2021 -0800
flatpak: allow setting data-dir for private repo
This can be used later on in testing to ensure that we are not perturbing
the user installation. The tests can specify a temporary directory so that
we can be sure we test the initial state.
src/plugins/flatpak/daemon/gnome-builder-flatpak.c | 5 +--
src/plugins/flatpak/daemon/ipc-flatpak-repo.c | 36 +++++++++++++++++-----
src/plugins/flatpak/daemon/ipc-flatpak-repo.h | 1 +
3 files changed, 33 insertions(+), 9 deletions(-)
---
diff --git a/src/plugins/flatpak/daemon/gnome-builder-flatpak.c
b/src/plugins/flatpak/daemon/gnome-builder-flatpak.c
index de90278ed..2dad7a5ce 100644
--- a/src/plugins/flatpak/daemon/gnome-builder-flatpak.c
+++ b/src/plugins/flatpak/daemon/gnome-builder-flatpak.c
@@ -150,9 +150,11 @@ log_func (const gchar *log_domain,
static int read_fileno = STDIN_FILENO;
static int write_fileno = STDOUT_FILENO;
+static char *data_dir;
static GOptionEntry main_entries[] = {
{ "read-fd", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &read_fileno },
{ "write-fd", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &write_fileno },
+ { "data-dir", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, &data_dir },
{ 0 }
};
@@ -205,8 +207,7 @@ main (gint argc,
g_dbus_connection_set_exit_on_close (connection, FALSE);
g_signal_connect_swapped (connection, "closed", G_CALLBACK (g_main_loop_quit), main_loop);
- /* Setup private flatpak installation immediately */
- (void)ipc_flatpak_repo_get_default ();
+ ipc_flatpak_repo_load (data_dir);
service = ipc_flatpak_service_impl_new ();
diff --git a/src/plugins/flatpak/daemon/ipc-flatpak-repo.c b/src/plugins/flatpak/daemon/ipc-flatpak-repo.c
index 99b8ec639..a5a8d6f01 100644
--- a/src/plugins/flatpak/daemon/ipc-flatpak-repo.c
+++ b/src/plugins/flatpak/daemon/ipc-flatpak-repo.c
@@ -39,6 +39,8 @@ allow runtime/org.kde.*\n\
";
static const char *remotes[] = { "flathub", "flathub-beta", "gnome-nightly" };
+static char *repo_data_dir;
+static IpcFlatpakRepo *instance;
static void
ipc_flatpak_repo_constructed (GObject *object)
@@ -57,7 +59,7 @@ ipc_flatpak_repo_constructed (GObject *object)
G_OBJECT_CLASS (ipc_flatpak_repo_parent_class)->constructed (object);
- flatpak = g_file_new_build_filename (g_get_user_data_dir (), "gnome-builder", "flatpak", NULL);
+ flatpak = g_file_new_build_filename (repo_data_dir, "flatpak", NULL);
filter_file = g_file_get_child (flatpak, "filter");
etc = g_file_get_child (flatpak, "etc");
installations_d = g_file_get_child (etc, "installations.d");
@@ -160,6 +162,11 @@ ipc_flatpak_repo_class_init (IpcFlatpakRepoClass *klass)
object_class->constructed = ipc_flatpak_repo_constructed;
object_class->finalize = ipc_flatpak_repo_finalize;
+
+ if (repo_data_dir == NULL)
+ repo_data_dir = g_build_filename (g_get_user_data_dir (),
+ "gnome-builder",
+ NULL);
}
static void
@@ -170,8 +177,6 @@ ipc_flatpak_repo_init (IpcFlatpakRepo *self)
IpcFlatpakRepo *
ipc_flatpak_repo_get_default (void)
{
- static IpcFlatpakRepo *instance;
-
if (!instance)
{
instance = g_object_new (IPC_TYPE_FLATPAK_REPO, NULL);
@@ -208,13 +213,30 @@ ipc_flatpak_repo_get_path (IpcFlatpakRepo *self)
char *
ipc_flatpak_repo_get_config_dir (IpcFlatpakRepo *self)
{
- g_autoptr(GFile) path = NULL;
-
g_return_val_if_fail (IPC_IS_FLATPAK_REPO (self), NULL);
- return g_build_filename (g_get_user_data_dir (),
- "gnome-builder",
+ return g_build_filename (repo_data_dir,
"etc",
"flatpak",
NULL);
}
+
+void
+ipc_flatpak_repo_load (const char *data_dir)
+{
+ if (instance != NULL)
+ {
+ g_critical ("Cannot load repo, already loaded");
+ return;
+ }
+
+ if (g_strcmp0 (data_dir, repo_data_dir) != 0)
+ {
+ g_free (repo_data_dir);
+ repo_data_dir = g_strdup (data_dir);
+ }
+
+ (void)ipc_flatpak_repo_get_default ();
+
+ g_return_if_fail (IPC_IS_FLATPAK_REPO (instance));
+}
diff --git a/src/plugins/flatpak/daemon/ipc-flatpak-repo.h b/src/plugins/flatpak/daemon/ipc-flatpak-repo.h
index f96c7f97a..1f71aa1d5 100644
--- a/src/plugins/flatpak/daemon/ipc-flatpak-repo.h
+++ b/src/plugins/flatpak/daemon/ipc-flatpak-repo.h
@@ -29,6 +29,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (IpcFlatpakRepo, ipc_flatpak_repo, IPC, FLATPAK_REPO, GObject)
IpcFlatpakRepo *ipc_flatpak_repo_get_default (void);
+void ipc_flatpak_repo_load (const char *data_dir);
FlatpakInstallation *ipc_flatpak_repo_get_installation (IpcFlatpakRepo *self);
char *ipc_flatpak_repo_get_path (IpcFlatpakRepo *self);
char *ipc_flatpak_repo_get_config_dir (IpcFlatpakRepo *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]