From 9d97382f822fc561efed632e87508d492db69eaa Mon Sep 17 00:00:00 2001 From: Mario Sanchez Prada Date: Fri, 16 Dec 2016 19:17:26 +0000 Subject: [PATCH] Add internal API: flatpak_dir_get_system_by_id() It will return a FlatpakDir by ID, according to the configuration. --- common/flatpak-dir.c | 43 +++++++++++++++++++++++++++++++++++++++++++ common/flatpak-dir.h | 3 +++ 2 files changed, 46 insertions(+) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index d8e66f27..4baa508c 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -5864,6 +5864,49 @@ flatpak_dir_get_system_default (void) return flatpak_dir_new_with_id (path, FALSE, NULL); } +FlatpakDir * +flatpak_dir_get_system_by_id (const char *id, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(GError) local_error = NULL; + GPtrArray *locations = NULL; + FlatpakDir *ret = NULL; + int i; + + if (id == NULL) + return flatpak_dir_get_system_default (); + + /* An error in flatpak_get_system_base_dir_locations() will still return + * return an empty array with the GError set, but we want to return NULL. + */ + locations = flatpak_get_system_base_dir_locations (cancellable, &local_error); + if (local_error != NULL) + { + g_propagate_error (error, g_steal_pointer (&local_error)); + return NULL; + } + + for (i = 0; i < locations->len; i++) + { + GFile *path = g_ptr_array_index (locations, i); + char *install_id = g_object_get_data (G_OBJECT (path), "installation-id"); + if (g_strcmp0 (install_id, id) == 0) + { + ret = flatpak_dir_new_with_id (path, FALSE, id); + break; + } + } + + if (ret == NULL) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + _("Could not find installation %s"), id); + } + + return ret; +} + GPtrArray * flatpak_dir_get_system_list (GCancellable *cancellable, GError **error) diff --git a/common/flatpak-dir.h b/common/flatpak-dir.h index a866d3cf..8eb04c79 100644 --- a/common/flatpak-dir.h +++ b/common/flatpak-dir.h @@ -148,6 +148,9 @@ FlatpakDir *flatpak_dir_get_user (void); FlatpakDir *flatpak_dir_get_system_default (void); GPtrArray *flatpak_dir_get_system_list (GCancellable *cancellable, GError **error); +FlatpakDir *flatpak_dir_get_system_by_id (const char *id, + GCancellable *cancellable, + GError **error); gboolean flatpak_dir_is_user (FlatpakDir *self); void flatpak_dir_set_no_system_helper (FlatpakDir *self, gboolean no_system_helper);