From ad11954bf7b0f3e75fbc29bc9765e0746dc221c7 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 25 Apr 2019 17:21:14 +0200 Subject: [PATCH] lib: Add a flag-using _full version of list/fetch_remote_ref This adds the flag FLATPAK_QUERY_FLAGS_ONLY_CACHED to use the new code for this. Closes: #2859 Approved by: alexlarsson --- common/flatpak-installation.c | 63 +++++++++++++++++++++++++++++++++-- common/flatpak-installation.h | 30 +++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/common/flatpak-installation.c b/common/flatpak-installation.c index 5781edfa..19d5a0ac 100644 --- a/common/flatpak-installation.c +++ b/common/flatpak-installation.c @@ -2342,6 +2342,31 @@ flatpak_installation_list_remote_refs_sync (FlatpakInstallation *self, const char *remote_or_uri, GCancellable *cancellable, GError **error) +{ + return flatpak_installation_list_remote_refs_sync_full (self, remote_or_uri, 0, cancellable, error); +} + +/** + * flatpak_installation_list_remote_refs_sync_full: + * @self: a #FlatpakInstallation + * @remote_or_uri: the name or URI of the remote + * @flags: set of #FlatpakQueryFlags + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Lists all the applications and runtimes in a remote. + * + * Returns: (transfer container) (element-type FlatpakRemoteRef): a GPtrArray of + * #FlatpakRemoteRef instances + * + * Since: 1.3.3 + */ +GPtrArray * +flatpak_installation_list_remote_refs_sync_full (FlatpakInstallation *self, + const char *remote_or_uri, + FlatpakQueryFlags flags, + GCancellable *cancellable, + GError **error) { g_autoptr(FlatpakDir) dir = NULL; g_autoptr(GPtrArray) refs = g_ptr_array_new_with_free_func (g_object_unref); @@ -2355,7 +2380,7 @@ flatpak_installation_list_remote_refs_sync (FlatpakInstallation *self, if (dir == NULL) return NULL; - state = flatpak_dir_get_remote_state (dir, remote_or_uri, FALSE, cancellable, error); + state = flatpak_dir_get_remote_state (dir, remote_or_uri, (flags & FLATPAK_QUERY_FLAGS_ONLY_CACHED) != 0, cancellable, error); if (state == NULL) return NULL; @@ -2403,6 +2428,40 @@ flatpak_installation_fetch_remote_ref_sync (FlatpakInstallation *self, const char *branch, GCancellable *cancellable, GError **error) +{ + return flatpak_installation_fetch_remote_ref_sync_full (self, remote_name, + kind, name, arch, branch, 0, + cancellable, error); +} + +/** + * flatpak_installation_fetch_remote_ref_sync_full: + * @self: a #FlatpakInstallation + * @remote_name: the name of the remote + * @kind: what this ref contains (an #FlatpakRefKind) + * @name: name of the app/runtime to fetch + * @arch: (nullable): which architecture to fetch (default: current architecture) + * @branch: (nullable): which branch to fetch (default: 'master') + * @flags: set of #FlatpakQueryFlags + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Gets the current remote branch of a ref in the remote. + * + * Returns: (transfer full): a #FlatpakRemoteRef instance, or %NULL + * + * Since: 1.3.3 + */ +FlatpakRemoteRef * +flatpak_installation_fetch_remote_ref_sync_full (FlatpakInstallation *self, + const char *remote_name, + FlatpakRefKind kind, + const char *name, + const char *arch, + const char *branch, + FlatpakQueryFlags flags, + GCancellable *cancellable, + GError **error) { g_autoptr(FlatpakDir) dir = NULL; g_autoptr(GHashTable) ht = NULL; @@ -2419,7 +2478,7 @@ flatpak_installation_fetch_remote_ref_sync (FlatpakInstallation *self, if (dir == NULL) return NULL; - state = flatpak_dir_get_remote_state (dir, remote_name, FALSE, cancellable, error); + state = flatpak_dir_get_remote_state (dir, remote_name, (flags & FLATPAK_QUERY_FLAGS_ONLY_CACHED) != 0, cancellable, error); if (state == NULL) return NULL; diff --git a/common/flatpak-installation.h b/common/flatpak-installation.h index 77bc3887..8d52ed7a 100644 --- a/common/flatpak-installation.h +++ b/common/flatpak-installation.h @@ -121,6 +121,22 @@ typedef enum { FLATPAK_LAUNCH_FLAGS_DO_NOT_REAP = (1 << 0), } FlatpakLaunchFlags; +/** + * FlatpakQueryFlags: + * @FLATPAK_QUERY_FLAGS_NONE: Default + * @FLATPAK_QUERY_FLAGS_ONLY_CACHED: Don't do any network i/o, but only return cached data. + * This can return stale data, or a #FLATPAK_ERROR_NOT_CACHED error, however it is a + * lot more efficient if you're doing many requests. + * + * Flags to alter the behavior of e.g flatpak_installation_list_remote_refs_full(). + * + * Since: 1.3.3 + */ +typedef enum { + FLATPAK_QUERY_FLAGS_NONE = 0, + FLATPAK_QUERY_FLAGS_ONLY_CACHED = (1 << 0), +} FlatpakQueryFlags; + /** * FlatpakStorageType: * @FLATPAK_STORAGE_TYPE_DEFAULT: default @@ -369,6 +385,11 @@ FLATPAK_EXTERN GPtrArray * flatpak_installation_list_remote_refs_sync (Fla const char *remote_or_uri, GCancellable *cancellable, GError **error); +FLATPAK_EXTERN GPtrArray * flatpak_installation_list_remote_refs_sync_full (FlatpakInstallation *self, + const char *remote_or_uri, + FlatpakQueryFlags flags, + GCancellable *cancellable, + GError **error); FLATPAK_EXTERN FlatpakRemoteRef *flatpak_installation_fetch_remote_ref_sync (FlatpakInstallation *self, const char *remote_name, FlatpakRefKind kind, @@ -377,6 +398,15 @@ FLATPAK_EXTERN FlatpakRemoteRef *flatpak_installation_fetch_remote_ref_sync (Fl const char *branch, GCancellable *cancellable, GError **error); +FLATPAK_EXTERN FlatpakRemoteRef *flatpak_installation_fetch_remote_ref_sync_full (FlatpakInstallation *self, + const char *remote_name, + FlatpakRefKind kind, + const char *name, + const char *arch, + const char *branch, + FlatpakQueryFlags flags, + GCancellable *cancellable, + GError **error); FLATPAK_EXTERN gboolean flatpak_installation_update_appstream_sync (FlatpakInstallation *self, const char *remote_name, const char *arch,