From fce0c052321ca2fe383bb717e2db8ab22312db43 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 10 Jul 2023 18:43:23 +0100 Subject: [PATCH 1/4] app: Provide a stub implementation of AS_CHECK_VERSION if needed Our only code that is conditional on the libappstream version wants version 0.14.0, which conveniently is exactly the version that introduced AS_CHECK_VERSION. Signed-off-by: Simon McVittie --- app/flatpak-builtins-utils.c | 2 +- app/flatpak-builtins-utils.h | 6 ++++++ configure.ac | 3 --- meson.build | 4 ---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/flatpak-builtins-utils.c b/app/flatpak-builtins-utils.c index 83d46551faa8..9373a0414ede 100644 --- a/app/flatpak-builtins-utils.c +++ b/app/flatpak-builtins-utils.c @@ -1130,7 +1130,7 @@ flatpak_dir_load_appstream_store (FlatpakDir *self, appstream_file = g_file_new_for_path (appstream_path); as_metadata_set_format_style (mdata, AS_FORMAT_STYLE_COLLECTION); -#ifdef HAVE_APPSTREAM_0_14_0 +#if AS_CHECK_VERSION(0, 14, 0) success = as_metadata_parse_file (mdata, appstream_file, AS_FORMAT_KIND_XML, &local_error); #else as_metadata_parse_file (mdata, appstream_file, AS_FORMAT_KIND_XML, &local_error); diff --git a/app/flatpak-builtins-utils.h b/app/flatpak-builtins-utils.h index 0189315761e3..958cd79a42f0 100644 --- a/app/flatpak-builtins-utils.h +++ b/app/flatpak-builtins-utils.h @@ -28,6 +28,12 @@ #include "flatpak-dir-private.h" #include "flatpak-permission-dbus-generated.h" +/* AS_CHECK_VERSION was introduced in 0.14.0; we still support 0.12.0, so + * behave as though versions without this macro are arbitrarily old */ +#ifndef AS_CHECK_VERSION +#define AS_CHECK_VERSION(major, minor, micro) (0) +#endif + /* Appstream data expires after a day */ #define FLATPAK_APPSTREAM_TTL 86400 diff --git a/configure.ac b/configure.ac index aaffba7fb6c9..6f8e6c325ba7 100644 --- a/configure.ac +++ b/configure.ac @@ -362,9 +362,6 @@ PKG_CHECK_MODULES(OSTREE, [ostree-1 >= $OSTREE_REQS]) PKG_CHECK_MODULES(JSON, [json-glib-1.0]) PKG_CHECK_MODULES(APPSTREAM, [appstream >= 0.12.0]) -PKG_CHECK_MODULES(APPSTREAM_0_14_0, appstream >= 0.14.0, - [AC_DEFINE([HAVE_APPSTREAM_0_14_0], [1], [Define if appstream >= 0.14.0 is available])], - [true]) PKG_CHECK_MODULES(GDK_PIXBUF, [gdk-pixbuf-2.0]) diff --git a/meson.build b/meson.build index b27338f518d6..6a85f474769b 100644 --- a/meson.build +++ b/meson.build @@ -363,10 +363,6 @@ if glib_dep.version().version_compare('>=2.60') cdata.set('GLIB_VERSION_MIN_REQUIRED', 'GLIB_VERSION_2_60') endif -if appstream_dep.version().version_compare('>=0.14.0') - cdata.set('HAVE_APPSTREAM_0_14_0', 1) -endif - if dconf_dep.found() cdata.set('HAVE_DCONF', 1) endif -- 2.41.0 From c51cf18d142fa5866f7de383bf1546276c73b227 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 10 Jul 2023 18:44:49 +0100 Subject: [PATCH 2/4] app: Use AS_FORMAT_STYLE_CATALOG if available AS_FORMAT_STYLE_COLLECTION is a deprecated alias for ..._CATALOG, and was removed entirely in appstream git main (presumably version 0.17 or 1.0). Resolves: https://github.com/flatpak/flatpak/issues/5472 Signed-off-by: Simon McVittie --- app/flatpak-builtins-utils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/flatpak-builtins-utils.c b/app/flatpak-builtins-utils.c index 9373a0414ede..1e9bcd3eef55 100644 --- a/app/flatpak-builtins-utils.c +++ b/app/flatpak-builtins-utils.c @@ -1129,7 +1129,12 @@ flatpak_dir_load_appstream_store (FlatpakDir *self, NULL); appstream_file = g_file_new_for_path (appstream_path); +#if AS_CHECK_VERSION(0, 16, 0) + as_metadata_set_format_style (mdata, AS_FORMAT_STYLE_CATALOG); +#else + /* Deprecated name for the same thing */ as_metadata_set_format_style (mdata, AS_FORMAT_STYLE_COLLECTION); +#endif #if AS_CHECK_VERSION(0, 14, 0) success = as_metadata_parse_file (mdata, appstream_file, AS_FORMAT_KIND_XML, &local_error); #else -- 2.41.0 From 83f376f37809fc43b4c1a68d27eb875a800835b0 Mon Sep 17 00:00:00 2001 From: Timo Eisenmann <141955678+eit47@users.noreply.github.com> Date: Sun, 17 Sep 2023 18:10:04 +0200 Subject: [PATCH 3/4] remote-info: Fix call to flatpak_dir_load_appstream_store() Use architecture instead of id in call to flatpak_dir_load_appstream_store (). Without this, remote-info does not show AppStream metadata. Fixes: adb3b61f "decomposed: Return FlatpakDecomposed from flatpak_dir_find_remote_ref()" --- app/flatpak-builtins-remote-info.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/flatpak-builtins-remote-info.c b/app/flatpak-builtins-remote-info.c index bec93e89e852..5f6b737c3fe8 100644 --- a/app/flatpak-builtins-remote-info.c +++ b/app/flatpak-builtins-remote-info.c @@ -183,11 +183,11 @@ flatpak_builtin_remote_info (int argc, char **argv, GCancellable *cancellable, G AsComponent *app = NULL; const char *version = NULL; const char *license = NULL; - g_autofree char *id = flatpak_decomposed_dup_id (ref); + g_autofree char *arch = flatpak_decomposed_dup_arch (ref); flatpak_get_window_size (&rows, &cols); - flatpak_dir_load_appstream_store (preferred_dir, remote, id, mdata, NULL, NULL); + flatpak_dir_load_appstream_store (preferred_dir, remote, arch, mdata, NULL, NULL); app = as_store_find_app (mdata, flatpak_decomposed_get_ref (ref)); if (app) { @@ -267,9 +267,9 @@ flatpak_builtin_remote_info (int argc, char **argv, GCancellable *cancellable, G width = cols - (len + 1); - print_aligned (len, _("ID:"), id); + print_aligned_take (len, _("ID:"), flatpak_decomposed_dup_id (ref)); print_aligned (len, _("Ref:"), flatpak_decomposed_get_ref (ref)); - print_aligned_take (len, _("Arch:"), flatpak_decomposed_dup_arch (ref)); + print_aligned (len, _("Arch:"), arch); print_aligned_take (len, _("Branch:"), flatpak_decomposed_dup_branch (ref)); if (version != NULL) print_aligned (len, _("Version:"), version); -- 2.41.0 From 51799bc16ae8eb536f0be09b73d6d9cd7078569d Mon Sep 17 00:00:00 2001 From: Matthias Klumpp Date: Sun, 8 Oct 2023 20:55:12 +0200 Subject: [PATCH 4/4] Adjust to AppStream 1.0 API changes --- app/flatpak-builtins-remote-info.c | 16 +++---- app/flatpak-builtins-remote-ls.c | 16 +++---- app/flatpak-builtins-search.c | 17 ++++++-- app/flatpak-builtins-utils.c | 69 +++++++++++++++++++++--------- app/flatpak-builtins-utils.h | 20 ++++----- 5 files changed, 88 insertions(+), 50 deletions(-) diff --git a/app/flatpak-builtins-remote-info.c b/app/flatpak-builtins-remote-info.c index 5f6b737c3fe8..501c102055dd 100644 --- a/app/flatpak-builtins-remote-info.c +++ b/app/flatpak-builtins-remote-info.c @@ -180,24 +180,24 @@ flatpak_builtin_remote_info (int argc, char **argv, GCancellable *cancellable, G int rows, cols; int width; g_autoptr(AsMetadata) mdata = as_metadata_new (); - AsComponent *app = NULL; + AsComponent *cpt = NULL; const char *version = NULL; const char *license = NULL; g_autofree char *arch = flatpak_decomposed_dup_arch (ref); flatpak_get_window_size (&rows, &cols); - flatpak_dir_load_appstream_store (preferred_dir, remote, arch, mdata, NULL, NULL); - app = as_store_find_app (mdata, flatpak_decomposed_get_ref (ref)); - if (app) + flatpak_dir_load_appstream_data (preferred_dir, remote, arch, mdata, NULL, NULL); + cpt = metadata_find_component (mdata, flatpak_decomposed_get_ref (ref)); + if (cpt) { - const char *name = as_component_get_name (app); - const char *comment = as_component_get_summary (app); + const char *name = as_component_get_name (cpt); + const char *comment = as_component_get_summary (cpt); print_wrapped (MIN (cols, 80), "\n%s - %s\n", name, comment); - version = as_app_get_version (app); - license = as_component_get_project_license (app); + version = component_get_version_latest (cpt); + license = as_component_get_project_license (cpt); } if (commit_v) diff --git a/app/flatpak-builtins-remote-ls.c b/app/flatpak-builtins-remote-ls.c index 1da12439ae00..fd718c9fb6be 100644 --- a/app/flatpak-builtins-remote-ls.c +++ b/app/flatpak-builtins-remote-ls.c @@ -231,7 +231,7 @@ ls_remote (GHashTable *refs_hash, const char **arches, const char *app_runtime, if (need_appstream_data) { mdata = as_metadata_new (); - flatpak_dir_load_appstream_store (dir, remote, NULL, mdata, NULL, NULL); + flatpak_dir_load_appstream_data (dir, remote, NULL, mdata, NULL, NULL); } keys = (FlatpakDecomposed **) g_hash_table_get_keys_as_array (names, &n_keys); @@ -244,7 +244,7 @@ ls_remote (GHashTable *refs_hash, const char **arches, const char *app_runtime, guint64 installed_size; guint64 download_size; g_autofree char *runtime = NULL; - AsComponent *app = NULL; + AsComponent *cpt = NULL; gboolean has_sparse_cache; VarMetadataRef sparse_cache; g_autofree char *id = flatpak_decomposed_dup_id (ref); @@ -278,7 +278,7 @@ ls_remote (GHashTable *refs_hash, const char **arches, const char *app_runtime, } if (need_appstream_data) - app = as_store_find_app (mdata, ref_str); + cpt = metadata_find_component (mdata, ref_str); if (app_runtime && runtime) { @@ -296,8 +296,8 @@ ls_remote (GHashTable *refs_hash, const char **arches, const char *app_runtime, const char *name = NULL; g_autofree char *readable_id = NULL; - if (app) - name = as_component_get_name (app); + if (cpt) + name = as_component_get_name (cpt); if (name == NULL) readable_id = flatpak_decomposed_dup_readable_id (ref); @@ -307,13 +307,13 @@ ls_remote (GHashTable *refs_hash, const char **arches, const char *app_runtime, else if (strcmp (columns[j].name, "description") == 0) { const char *comment = NULL; - if (app) - comment = as_component_get_summary (app); + if (cpt) + comment = as_component_get_summary (cpt); flatpak_table_printer_add_column (printer, comment); } else if (strcmp (columns[j].name, "version") == 0) - flatpak_table_printer_add_column (printer, app ? as_app_get_version (app) : ""); + flatpak_table_printer_add_column (printer, cpt ? component_get_version_latest (cpt) : ""); else if (strcmp (columns[j].name, "ref") == 0) flatpak_table_printer_add_column (printer, ref_str); else if (strcmp (columns[j].name, "application") == 0) diff --git a/app/flatpak-builtins-search.c b/app/flatpak-builtins-search.c index 6a8ff80cd386..3c85e4e9b917 100644 --- a/app/flatpak-builtins-search.c +++ b/app/flatpak-builtins-search.c @@ -76,7 +76,7 @@ get_remote_stores (GPtrArray *dirs, const char *arch, GCancellable *cancellable) { g_autoptr(AsMetadata) mdata = as_metadata_new (); - flatpak_dir_load_appstream_store (dir, remotes[j], arch, mdata, cancellable, &error); + flatpak_dir_load_appstream_data (dir, remotes[j], arch, mdata, cancellable, &error); if (error) { @@ -185,7 +185,7 @@ component_get_branch (AsComponent *app) static void print_app (Column *columns, MatchResult *res, FlatpakTablePrinter *printer) { - const char *version = as_app_get_version (res->app); + const char *version = component_get_version_latest (res->app); g_autofree char *id = component_get_flatpak_id (res->app); const char *name = as_component_get_name (res->app); const char *comment = as_component_get_summary (res->app); @@ -272,12 +272,21 @@ flatpak_builtin_search (int argc, char **argv, GCancellable *cancellable, GError for (j = 0; j < remote_stores->len; ++j) { AsMetadata *mdata = g_ptr_array_index (remote_stores, j); +#if AS_CHECK_VERSION(1, 0, 0) + AsComponentBox *apps = as_metadata_get_components (mdata); +#else GPtrArray *apps = as_metadata_get_components (mdata); - guint i; +#endif - for (i = 0; i < apps->len; ++i) +#if AS_CHECK_VERSION(1, 0, 0) + for (guint i = 0; i < as_component_box_len (apps); ++i) + { + AsComponent *app = as_component_box_index (apps, i); +#else + for (guint i = 0; i < apps->len; ++i) { AsComponent *app = g_ptr_array_index (apps, i); +#endif const char *remote_name = g_object_get_data (G_OBJECT (mdata), "remote-name"); g_autoptr(FlatpakDecomposed) decomposed = NULL; diff --git a/app/flatpak-builtins-utils.c b/app/flatpak-builtins-utils.c index 1e9bcd3eef55..18b1852c0c1a 100644 --- a/app/flatpak-builtins-utils.c +++ b/app/flatpak-builtins-utils.c @@ -1042,50 +1042,79 @@ ellipsize_string_full (const char *text, int len, FlatpakEllipsizeMode mode) } const char * -as_app_get_version (AsComponent *app) +component_get_version_latest (AsComponent *component) { - GPtrArray *releases = as_component_get_releases (app); +#if AS_CHECK_VERSION(1, 0, 0) + AsReleaseList *releases = NULL; + + /* load releases without network access, ignoring any errors */ + as_component_load_releases (component, FALSE, NULL); + + /* fetch default releases even if previous loading has failed */ + releases = as_component_get_releases_plain (component); + if (releases != NULL && as_release_list_len (releases) > 0) + return as_release_get_version (as_release_list_index (releases, 0)); +#else + GPtrArray *releases = as_component_get_releases (component); if (releases != NULL && releases->len > 0) return as_release_get_version (AS_RELEASE (g_ptr_array_index (releases, 0))); +#endif return NULL; } AsComponent * -as_store_find_app (AsMetadata *mdata, - const char *ref) +metadata_find_component (AsMetadata *mdata, + const char *ref) { g_autoptr(FlatpakRef) rref = flatpak_ref_parse (ref, NULL); - const char *appid = flatpak_ref_get_name (rref); - g_autofree char *desktopid = g_strconcat (appid, ".desktop", NULL); - int j; + const char *cid = flatpak_ref_get_name (rref); + g_autofree char *desktopid = g_strconcat (cid, ".desktop", NULL); - for (j = 0; j < 2; j++) + for (int j = 0; j < 2; j++) { - const char *id = j == 0 ? appid : desktopid; + const char *id = j == 0 ? cid : desktopid; +#if AS_CHECK_VERSION(1, 0, 0) + AsComponentBox *cbox = as_metadata_get_components (mdata); + + for (gsize i = 0; i < as_component_box_len (cbox); i++) + { + AsComponent *component = as_component_box_index (cbox, i); + AsBundle *bundle; + + if (g_strcmp0 (as_component_get_id (component), id) != 0) + continue; + + bundle = as_component_get_bundle (component, AS_BUNDLE_KIND_FLATPAK); + if (bundle && + g_str_equal (as_bundle_get_id (bundle), ref)) + return component; + } +#else GPtrArray *components = as_metadata_get_components (mdata); for (gsize i = 0; i < components->len; i++) { - AsComponent *app = g_ptr_array_index (components, i); + AsComponent *component = g_ptr_array_index (components, i); AsBundle *bundle; - if (g_strcmp0 (as_component_get_id (app), id) != 0) + if (g_strcmp0 (as_component_get_id (component), id) != 0) continue; - bundle = as_component_get_bundle (app, AS_BUNDLE_KIND_FLATPAK); + bundle = as_component_get_bundle (component, AS_BUNDLE_KIND_FLATPAK); if (bundle && g_str_equal (as_bundle_get_id (bundle), ref)) - return app; + return component; } +#endif } return NULL; } /** - * flatpak_dir_load_appstream_store: + * flatpak_dir_load_appstream_data: * @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, @@ -1103,12 +1132,12 @@ as_store_find_app (AsMetadata *mdata, * otherwise */ gboolean -flatpak_dir_load_appstream_store (FlatpakDir *self, - const gchar *remote_name, - const gchar *arch, - AsMetadata *mdata, - GCancellable *cancellable, - GError **error) +flatpak_dir_load_appstream_data (FlatpakDir *self, + const gchar *remote_name, + const gchar *arch, + AsMetadata *mdata, + GCancellable *cancellable, + GError **error) { const char *install_path = flatpak_file_get_path_cached (flatpak_dir_get_path (self)); g_autoptr(GFile) appstream_file = NULL; diff --git a/app/flatpak-builtins-utils.h b/app/flatpak-builtins-utils.h index 958cd79a42f0..257a6b952f67 100644 --- a/app/flatpak-builtins-utils.h +++ b/app/flatpak-builtins-utils.h @@ -160,16 +160,16 @@ void print_aligned_take (int len, const char *title, char *value); -AsComponent *as_store_find_app (AsMetadata *mdata, - const char *ref); -const char *as_app_get_version (AsComponent *component); - -gboolean flatpak_dir_load_appstream_store (FlatpakDir *self, - const gchar *remote_name, - const gchar *arch, - AsMetadata *mdata, - GCancellable *cancellable, - GError **error); +AsComponent *metadata_find_component (AsMetadata *mdata, + const char *ref); +const char *component_get_version_latest (AsComponent *component); + +gboolean flatpak_dir_load_appstream_data (FlatpakDir *self, + const gchar *remote_name, + const gchar *arch, + AsMetadata *mdata, + GCancellable *cancellable, + GError **error); int cell_width (const char *text); const char *cell_advance (const char *text, -- 2.41.0