Skip to content

Commit

Permalink
Add support for files generated by appstreamcli compose (#5277)
Browse files Browse the repository at this point in the history
Co-authored-by: Bartłomiej Piotrowski <[email protected]>
Co-authored-by: Jamie Murphy <[email protected]>
  • Loading branch information
3 people committed Feb 4, 2023
1 parent e72ae11 commit 88f7ecd
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 18 deletions.
12 changes: 6 additions & 6 deletions app/flatpak-builtins-build-bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,12 @@ get_bundle_appstream_data (GFile *root,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GFile) xmls_dir = NULL;
g_autofree char *appstream_basename = NULL;
g_autoptr(GFile) appstream_file = NULL;
g_autoptr(GInputStream) xml_in = NULL;

*result = NULL;

xmls_dir = g_file_resolve_relative_path (root, "files/share/app-info/xmls");
appstream_basename = g_strconcat (name, ".xml.gz", NULL);
appstream_file = g_file_get_child (xmls_dir, appstream_basename);

flatpak_appstream_get_xml_path (root, &appstream_file, NULL, name, NULL);

xml_in = (GInputStream *) g_file_read (appstream_file, cancellable, NULL);
if (xml_in)
Expand Down Expand Up @@ -177,6 +173,10 @@ iterate_bundle_icons (GFile *root,
g_autoptr(GFile) icons_dir =
g_file_resolve_relative_path (root,
"files/share/app-info/icons/flatpak");
if (!g_file_test (g_file_peek_path (icons_dir), G_FILE_TEST_IS_DIR)) {
icons_dir = g_file_resolve_relative_path (root,
"files/share/swcatalog/icons/flatpak");
}
const char *icon_sizes[] = { "64x64", "128x128" };
const char *icon_sizes_key[] = { "icon-64", "icon-128" };
g_autofree char *icon_name = g_strconcat (name, ".png", NULL);
Expand Down
4 changes: 1 addition & 3 deletions common/flatpak-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -3361,12 +3361,10 @@ static char *
read_appdata_xml_from_deploy_dir (GFile *deploy_dir, const char *id)
{
g_autoptr(GFile) appdata_file = NULL;
g_autofree char *appdata_name = NULL;
g_autoptr(GFileInputStream) appdata_in = NULL;
gsize size;

appdata_name = g_strconcat (id, ".xml.gz", NULL);
appdata_file = flatpak_build_file (deploy_dir, "files/share/app-info/xmls", appdata_name, NULL);
flatpak_appstream_get_xml_path (deploy_dir, &appdata_file, NULL, id, NULL);

appdata_in = g_file_read (appdata_file, NULL, NULL);
if (appdata_in)
Expand Down
12 changes: 11 additions & 1 deletion common/flatpak-installed-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ flatpak_installed_ref_load_appdata (FlatpakInstalledRef *self,
gsize length;
g_autofree char *path = NULL;
g_autofree char *appdata_name = NULL;
g_autofree char *appinfo_path = NULL;
g_autofree char *swcatalog_path = NULL;

if (priv->deploy_dir == NULL)
{
Expand All @@ -535,7 +537,15 @@ flatpak_installed_ref_load_appdata (FlatpakInstalledRef *self,
}

appdata_name = g_strconcat (flatpak_ref_get_name (FLATPAK_REF (self)), ".xml.gz", NULL);
path = g_build_filename (priv->deploy_dir, "files/share/app-info/xmls", appdata_name, NULL);
appinfo_path = g_build_filename (priv->deploy_dir, "files/share/app-info/xmls", appdata_name, NULL);
swcatalog_path = g_build_filename (priv->deploy_dir, "files/share/swcatalog/xml/flatpak.xml.gz", NULL);

if (g_file_test (appinfo_path, G_FILE_TEST_EXISTS))
path = g_steal_pointer (&appinfo_path);
else if (g_file_test (swcatalog_path, G_FILE_TEST_EXISTS))
path = g_steal_pointer (&swcatalog_path);
else
return NULL;

if (!g_file_get_contents (path, &data, &length, error))
return NULL;
Expand Down
6 changes: 6 additions & 0 deletions common/flatpak-utils-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,12 @@ void flatpak_appstream_xml_filter (FlatpakXml *appstream,
GRegex *allow_refs,
GRegex *deny_refs);

void flatpak_appstream_get_xml_path (GFile *root,
GFile **appstream_file_out,
GFile **app_info_dir_out,
const char *name,
GCancellable *cancellable);

char * flatpak_filter_glob_to_regexp (const char *glob, gboolean runtime_only, GError **error);
gboolean flatpak_parse_filters (const char *data,
GRegex **allow_refs_out,
Expand Down
39 changes: 31 additions & 8 deletions common/flatpak-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -5344,18 +5344,15 @@ extract_appstream (OstreeRepo *repo,
{
g_autoptr(GFile) root = NULL;
g_autoptr(GFile) app_info_dir = NULL;
g_autoptr(GFile) xmls_dir = NULL;
g_autoptr(GFile) icons_dir = NULL;
g_autoptr(GFile) appstream_file = NULL;
g_autoptr(GFile) metadata = NULL;
g_autofree char *appstream_basename = NULL;
g_autoptr(GInputStream) in = NULL;
g_autoptr(FlatpakXml) xml_root = NULL;
g_autoptr(GKeyFile) keyfile = NULL;

if (!ostree_repo_read_commit (repo, flatpak_decomposed_get_ref (ref), &root, NULL, NULL, error))
return FALSE;

keyfile = g_key_file_new ();
metadata = g_file_get_child (root, "metadata");
if (g_file_query_exists (metadata, cancellable))
Expand All @@ -5370,14 +5367,10 @@ extract_appstream (OstreeRepo *repo,
return FALSE;
}

app_info_dir = g_file_resolve_relative_path (root, "files/share/app-info");
flatpak_appstream_get_xml_path (root, &appstream_file, &app_info_dir, id, NULL);

xmls_dir = g_file_resolve_relative_path (app_info_dir, "xmls");
icons_dir = g_file_resolve_relative_path (app_info_dir, "icons/flatpak");

appstream_basename = g_strconcat (id, ".xml.gz", NULL);
appstream_file = g_file_get_child (xmls_dir, appstream_basename);

in = (GInputStream *) g_file_read (appstream_file, cancellable, error);
if (!in)
return FALSE;
Expand Down Expand Up @@ -5955,6 +5948,36 @@ flatpak_repo_generate_appstream (OstreeRepo *repo,
return TRUE;
}

void
flatpak_appstream_get_xml_path (GFile *root,
GFile **appstream_file_out,
GFile **app_info_dir_out,
const char *name,
GCancellable *cancellable)
{
g_autoptr(GFile) appstream_file = NULL;
g_autoptr(GFile) app_info_dir = NULL;

appstream_file = g_file_resolve_relative_path (root, "files/share/swcatalog/xml/flatpak.xml.gz");
if (g_file_query_exists (appstream_file, cancellable))
app_info_dir = g_file_resolve_relative_path (root, "files/share/swcatalog");
{
g_autoptr(GFile) xmls_dir = NULL;
g_autofree char *appstream_basename = NULL;

g_clear_object (&appstream_file);
app_info_dir = g_file_resolve_relative_path (root, "files/share/app-info");
xmls_dir = g_file_resolve_relative_path (app_info_dir, "xmls");
appstream_basename = g_strconcat (name, ".xml.gz", NULL);
appstream_file = g_file_get_child (xmls_dir, appstream_basename);
}

if (app_info_dir_out)
*app_info_dir_out = g_steal_pointer (&app_info_dir);
if (appstream_file_out)
*appstream_file_out = g_steal_pointer (&appstream_file);
}

void
flatpak_extension_free (FlatpakExtension *extension)
{
Expand Down

0 comments on commit 88f7ecd

Please sign in to comment.