From fe1540f9887012af74e8a5ef9d368ff6faa51fb4 Mon Sep 17 00:00:00 2001 From: Mario Sanchez Prada Date: Fri, 16 Dec 2016 19:17:46 +0000 Subject: [PATCH] Add public API: flatpak_get_system_installations() It's meant to provide a list of the system installations, not just the default one, which can still be obtained by calling flatpak_installation_new_system(), as usual. --- lib/flatpak-installation.c | 57 ++++++++++++++++++++++++++++++++++++++ lib/flatpak-installation.h | 2 ++ 2 files changed, 59 insertions(+) diff --git a/lib/flatpak-installation.c b/lib/flatpak-installation.c index 7ba57841..5b9f2a27 100644 --- a/lib/flatpak-installation.c +++ b/lib/flatpak-installation.c @@ -174,6 +174,63 @@ flatpak_get_supported_arches (void) return (const char * const *)flatpak_get_arches (); } +/** + * flatpak_get_system_installations: + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Lists the system installations according to the current configuration and current + * availability (e.g. doesn't return a configured installation if not reachable). + * + * Returns: (transfer full) (element-type FlatpakInstallation): an GPtrArray of + * #FlatpakInstallation instances + * + * Since: 0.6.15 + */ +GPtrArray * +flatpak_get_system_installations (GCancellable *cancellable, + GError **error) +{ + g_autoptr(GPtrArray) system_dirs = NULL; + g_autoptr(GPtrArray) installs = NULL; + GPtrArray *ret = NULL; + int i; + + system_dirs = flatpak_dir_get_system_list (cancellable, error); + if (system_dirs == NULL) + goto out; + + installs = g_ptr_array_new (); + for (i = 0; i < system_dirs->len; i++) + { + g_autoptr(GError) local_error = NULL; + FlatpakDir *install_dir = g_ptr_array_index (system_dirs, i); + FlatpakInstallation *installation = NULL; + + installation = flatpak_installation_new_for_dir (g_object_ref (install_dir), + cancellable, + &local_error); + if (installation != NULL) + g_ptr_array_add (installs, installation); + else + { + g_warning ("Unable to create FlatpakInstallation for: %s", local_error->message); + g_propagate_error (error, g_steal_pointer (&local_error)); + goto out; + } + } + + if (installs->len == 0) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + "No system installations found"); + } + + ret = g_steal_pointer (&installs); + + out: + return ret; +} /** * flatpak_installation_new_system: diff --git a/lib/flatpak-installation.h b/lib/flatpak-installation.h index 1b059e41..4340d036 100644 --- a/lib/flatpak-installation.h +++ b/lib/flatpak-installation.h @@ -80,6 +80,8 @@ FLATPAK_EXTERN const char *flatpak_get_default_arch (void); FLATPAK_EXTERN const char *const *flatpak_get_supported_arches (void); +FLATPAK_EXTERN GPtrArray *flatpak_get_system_installations (GCancellable *cancellable, + GError **error); FLATPAK_EXTERN FlatpakInstallation *flatpak_installation_new_system (GCancellable *cancellable, GError **error); FLATPAK_EXTERN FlatpakInstallation *flatpak_installation_new_user (GCancellable *cancellable,