From 9dff4bbb852d3df62c0028d22b18fa9c5a43c69f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 11 Jan 2019 22:32:16 -0500 Subject: [PATCH] Move flatpak_dir_load_appstream_store This function has libappstream-glib types in the api, which we want to drop. And it is only used in app/, so move it there. Closes: #2580 Approved by: alexlarsson --- app/flatpak-builtins-utils.c | 61 ++++++++++++++++++++++++++++++++++++ app/flatpak-builtins-utils.h | 8 +++++ common/flatpak-dir-private.h | 7 ----- common/flatpak-dir.c | 60 ----------------------------------- 4 files changed, 69 insertions(+), 67 deletions(-) diff --git a/app/flatpak-builtins-utils.c b/app/flatpak-builtins-utils.c index 9c2af82f..b46dc320 100644 --- a/app/flatpak-builtins-utils.c +++ b/app/flatpak-builtins-utils.c @@ -1111,6 +1111,67 @@ as_store_find_app (AsStore *store, return NULL; } +/** + * flatpak_dir_load_appstream_store: + * @self: a #FlatpakDir + * @remote_name: name of the remote to load the AppStream data for + * @arch: (nullable): name of the architecture to load the AppStream data for, + * or %NULL to use the default + * @store: the store to load into + * @cancellable: (nullable): a #GCancellable, or %NULL + * @error: return location for a #GError + * + * Load the cached AppStream data for the given @remote_name into @store, which + * must have already been constructed using as_store_new(). If no cache + * exists, %FALSE is returned with no error set. If there is an error loading or + * parsing the cache, an error is returned. + * + * Returns: %TRUE if the cache exists and was loaded into @store; %FALSE + * otherwise + */ +gboolean +flatpak_dir_load_appstream_store (FlatpakDir *self, + const gchar *remote_name, + const gchar *arch, + AsStore *store, + GCancellable *cancellable, + GError **error) +{ + const char *install_path = flatpak_file_get_path_cached (flatpak_dir_get_path (self)); + g_autoptr(GFile) appstream_file = NULL; + g_autofree char *appstream_path = NULL; + g_autoptr(GError) local_error = NULL; + gboolean success; + + if (arch == NULL) + arch = flatpak_get_arch (); + + if (flatpak_dir_get_remote_oci (self, remote_name)) + appstream_path = g_build_filename (install_path, "appstream", remote_name, + arch, "appstream.xml.gz", + NULL); + else + appstream_path = g_build_filename (install_path, "appstream", remote_name, + arch, "active", "appstream.xml.gz", + NULL); + + appstream_file = g_file_new_for_path (appstream_path); + as_store_from_file (store, appstream_file, NULL, cancellable, &local_error); + success = (local_error == NULL); + + /* We want to ignore ENOENT error as it is harmless and valid + * FIXME: appstream-glib doesn't have granular file-not-found error + * See: https://github.com/hughsie/appstream-glib/pull/268 */ + if (local_error != NULL && + g_str_has_suffix (local_error->message, "No such file or directory")) + g_clear_error (&local_error); + else if (local_error != NULL) + g_propagate_error (error, g_steal_pointer (&local_error)); + + return success; +} + + void print_aligned (int len, const char *title, const char *value) { diff --git a/app/flatpak-builtins-utils.h b/app/flatpak-builtins-utils.h index 8542d497..fc448bc8 100644 --- a/app/flatpak-builtins-utils.h +++ b/app/flatpak-builtins-utils.h @@ -22,6 +22,7 @@ #define __FLATPAK_BUILTINS_UTILS_H__ #include +#include #include "libglnx/libglnx.h" #include "flatpak-utils-private.h" #include "flatpak-dir-private.h" @@ -151,6 +152,13 @@ const char *as_app_get_localized_name (AsApp *app); const char *as_app_get_localized_comment (AsApp *app); const char *as_app_get_version (AsApp *app); +gboolean flatpak_dir_load_appstream_store (FlatpakDir *self, + const gchar *remote_name, + const gchar *arch, + AsStore *store, + GCancellable *cancellable, + GError **error); + void print_wrapped (int columns, const char *text, ...) G_GNUC_PRINTF (2, 3); #endif /* __FLATPAK_BUILTINS_UTILS_H__ */ diff --git a/common/flatpak-dir-private.h b/common/flatpak-dir-private.h index fb1f1de1..b3c2bbe4 100644 --- a/common/flatpak-dir-private.h +++ b/common/flatpak-dir-private.h @@ -23,7 +23,6 @@ #include -#include #include "libglnx/libglnx.h" #include #include @@ -506,12 +505,6 @@ gboolean flatpak_dir_update_appstream (FlatpakDir *self, OstreeAsyncProgress *progress, GCancellable *cancellable, GError **error); -gboolean flatpak_dir_load_appstream_store (FlatpakDir *self, - const gchar *remote_name, - const gchar *arch, - AsStore *store, - GCancellable *cancellable, - GError **error); gboolean flatpak_dir_pull (FlatpakDir *self, FlatpakRemoteState *state, const char *ref, diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 12e0a8a1..e0ce7fdb 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -7703,66 +7703,6 @@ flatpak_dir_create_system_child_repo (FlatpakDir *self, return flatpak_dir_create_child_repo (self, cache_dir, file_lock, optional_commit, error); } -/** - * flatpak_dir_load_appstream_store: - * @self: a #FlatpakDir - * @remote_name: name of the remote to load the AppStream data for - * @arch: (nullable): name of the architecture to load the AppStream data for, - * or %NULL to use the default - * @store: the store to load into - * @cancellable: (nullable): a #GCancellable, or %NULL - * @error: return location for a #GError - * - * Load the cached AppStream data for the given @remote_name into @store, which - * must have already been constructed using as_store_new(). If no cache - * exists, %FALSE is returned with no error set. If there is an error loading or - * parsing the cache, an error is returned. - * - * Returns: %TRUE if the cache exists and was loaded into @store; %FALSE - * otherwise - */ -gboolean -flatpak_dir_load_appstream_store (FlatpakDir *self, - const gchar *remote_name, - const gchar *arch, - AsStore *store, - GCancellable *cancellable, - GError **error) -{ - const char *install_path = flatpak_file_get_path_cached (flatpak_dir_get_path (self)); - g_autoptr(GFile) appstream_file = NULL; - g_autofree char *appstream_path = NULL; - g_autoptr(GError) local_error = NULL; - gboolean success; - - if (arch == NULL) - arch = flatpak_get_arch (); - - if (flatpak_dir_get_remote_oci (self, remote_name)) - appstream_path = g_build_filename (install_path, "appstream", remote_name, - arch, "appstream.xml.gz", - NULL); - else - appstream_path = g_build_filename (install_path, "appstream", remote_name, - arch, "active", "appstream.xml.gz", - NULL); - - appstream_file = g_file_new_for_path (appstream_path); - as_store_from_file (store, appstream_file, NULL, cancellable, &local_error); - success = (local_error == NULL); - - /* We want to ignore ENOENT error as it is harmless and valid - * FIXME: appstream-glib doesn't have granular file-not-found error - * See: https://github.com/hughsie/appstream-glib/pull/268 */ - if (local_error != NULL && - g_str_has_suffix (local_error->message, "No such file or directory")) - g_clear_error (&local_error); - else if (local_error != NULL) - g_propagate_error (error, g_steal_pointer (&local_error)); - - return success; -} - gboolean flatpak_dir_install (FlatpakDir *self, gboolean no_pull,