forked from Mirrors/flatpak-builder
common: Break out xml appstream rewriting to helper functions
parent
c84ebe0440
commit
73defceec6
|
@ -1635,14 +1635,15 @@ validate_component (XdgAppXml *component,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
gboolean
|
||||||
migrate_xml (XdgAppXml *root,
|
xdg_app_appstream_xml_migrate (XdgAppXml *source,
|
||||||
XdgAppXml *appstream,
|
XdgAppXml *dest,
|
||||||
const char *ref,
|
const char *ref,
|
||||||
const char *id,
|
const char *id,
|
||||||
GKeyFile *metadata)
|
GKeyFile *metadata)
|
||||||
{
|
{
|
||||||
XdgAppXml *components;
|
XdgAppXml *source_components;
|
||||||
|
XdgAppXml *dest_components;
|
||||||
XdgAppXml *component;
|
XdgAppXml *component;
|
||||||
XdgAppXml *prev_component;
|
XdgAppXml *prev_component;
|
||||||
gboolean migrated = FALSE;
|
gboolean migrated = FALSE;
|
||||||
|
@ -1651,9 +1652,9 @@ migrate_xml (XdgAppXml *root,
|
||||||
g_autofree const char *sdk = NULL;
|
g_autofree const char *sdk = NULL;
|
||||||
const char *group;
|
const char *group;
|
||||||
|
|
||||||
if (root->first_child == NULL ||
|
if (source->first_child == NULL ||
|
||||||
root->first_child->next_sibling != NULL ||
|
source->first_child->next_sibling != NULL ||
|
||||||
g_strcmp0 (root->first_child->element_name, "components") != 0)
|
g_strcmp0 (source->first_child->element_name, "components") != 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (g_str_has_prefix (ref, "app/"))
|
if (g_str_has_prefix (ref, "app/"))
|
||||||
|
@ -1665,9 +1666,10 @@ migrate_xml (XdgAppXml *root,
|
||||||
runtime = g_key_file_get_string (metadata, group, "runtime", NULL);
|
runtime = g_key_file_get_string (metadata, group, "runtime", NULL);
|
||||||
sdk = g_key_file_get_string (metadata, group, "sdk", NULL);
|
sdk = g_key_file_get_string (metadata, group, "sdk", NULL);
|
||||||
|
|
||||||
components = root->first_child;
|
source_components = source->first_child;
|
||||||
|
dest_components = dest->first_child;
|
||||||
|
|
||||||
component = components->first_child;
|
component = source_components->first_child;
|
||||||
prev_component = NULL;
|
prev_component = NULL;
|
||||||
while (component != NULL)
|
while (component != NULL)
|
||||||
{
|
{
|
||||||
|
@ -1675,7 +1677,8 @@ migrate_xml (XdgAppXml *root,
|
||||||
|
|
||||||
if (validate_component (component, ref, id, tags, runtime, sdk))
|
if (validate_component (component, ref, id, tags, runtime, sdk))
|
||||||
{
|
{
|
||||||
xdg_app_xml_add (appstream, xdg_app_xml_unlink (component, prev_component));
|
xdg_app_xml_add (dest_components,
|
||||||
|
xdg_app_xml_unlink (component, prev_component));
|
||||||
migrated = TRUE;
|
migrated = TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1731,7 +1734,7 @@ copy_icon (const char *id,
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
extract_appstream (OstreeRepo *repo,
|
extract_appstream (OstreeRepo *repo,
|
||||||
XdgAppXml *appstream_components,
|
XdgAppXml *appstream_root,
|
||||||
const char *ref,
|
const char *ref,
|
||||||
const char *id,
|
const char *id,
|
||||||
GFile *dest,
|
GFile *dest,
|
||||||
|
@ -1776,7 +1779,8 @@ extract_appstream (OstreeRepo *repo,
|
||||||
if (xml_root == NULL)
|
if (xml_root == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (migrate_xml (xml_root, appstream_components, ref, id, keyfile))
|
if (xdg_app_appstream_xml_migrate (xml_root, appstream_root,
|
||||||
|
ref, id, keyfile))
|
||||||
{
|
{
|
||||||
g_autoptr(GError) my_error = NULL;
|
g_autoptr(GError) my_error = NULL;
|
||||||
if (!copy_icon (id, root, dest, "64x64", &my_error))
|
if (!copy_icon (id, root, dest, "64x64", &my_error))
|
||||||
|
@ -1794,6 +1798,28 @@ extract_appstream (OstreeRepo *repo,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XdgAppXml *
|
||||||
|
xdg_app_appstream_xml_new (void)
|
||||||
|
{
|
||||||
|
XdgAppXml *appstream_root = NULL;
|
||||||
|
XdgAppXml *appstream_components;
|
||||||
|
|
||||||
|
appstream_root = xdg_app_xml_new ("root");
|
||||||
|
appstream_components = xdg_app_xml_new ("components");
|
||||||
|
xdg_app_xml_add (appstream_root, appstream_components);
|
||||||
|
xdg_app_xml_add (appstream_components, xdg_app_xml_new_text ("\n "));
|
||||||
|
|
||||||
|
appstream_components->attribute_names = g_new0 (char *, 3);
|
||||||
|
appstream_components->attribute_values = g_new0 (char *, 3);
|
||||||
|
appstream_components->attribute_names[0] = g_strdup ("version");
|
||||||
|
appstream_components->attribute_values[0] = g_strdup ("0.8");
|
||||||
|
appstream_components->attribute_names[1] = g_strdup ("origin");
|
||||||
|
appstream_components->attribute_values[1] = g_strdup ("xdg-app");
|
||||||
|
|
||||||
|
return appstream_root;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
xdg_app_repo_generate_appstream (OstreeRepo *repo,
|
xdg_app_repo_generate_appstream (OstreeRepo *repo,
|
||||||
const char **gpg_key_ids,
|
const char **gpg_key_ids,
|
||||||
|
@ -1848,7 +1874,6 @@ xdg_app_repo_generate_appstream (OstreeRepo *repo,
|
||||||
g_autofree char *parent = NULL;
|
g_autofree char *parent = NULL;
|
||||||
g_autofree char *branch = NULL;
|
g_autofree char *branch = NULL;
|
||||||
g_autoptr(XdgAppXml) appstream_root = NULL;
|
g_autoptr(XdgAppXml) appstream_root = NULL;
|
||||||
XdgAppXml *appstream_components;
|
|
||||||
g_autoptr(GString) xml = NULL;
|
g_autoptr(GString) xml = NULL;
|
||||||
g_autoptr(GZlibCompressor) compressor = NULL;
|
g_autoptr(GZlibCompressor) compressor = NULL;
|
||||||
g_autoptr(GOutputStream) out2 = NULL;
|
g_autoptr(GOutputStream) out2 = NULL;
|
||||||
|
@ -1859,17 +1884,7 @@ xdg_app_repo_generate_appstream (OstreeRepo *repo,
|
||||||
|
|
||||||
tmpdir_file = g_file_new_for_path (tmpdir);
|
tmpdir_file = g_file_new_for_path (tmpdir);
|
||||||
|
|
||||||
appstream_root = xdg_app_xml_new ("root");
|
appstream_root = xdg_app_appstream_xml_new ();
|
||||||
appstream_components = xdg_app_xml_new ("components");
|
|
||||||
xdg_app_xml_add (appstream_root, appstream_components);
|
|
||||||
xdg_app_xml_add (appstream_components, xdg_app_xml_new_text ("\n "));
|
|
||||||
|
|
||||||
appstream_components->attribute_names = g_new0 (char *, 3);
|
|
||||||
appstream_components->attribute_values = g_new0 (char *, 3);
|
|
||||||
appstream_components->attribute_names[0] = g_strdup ("version");
|
|
||||||
appstream_components->attribute_values[0] = g_strdup ("0.8");
|
|
||||||
appstream_components->attribute_names[1] = g_strdup ("origin");
|
|
||||||
appstream_components->attribute_values[1] = g_strdup ("xdg-app");
|
|
||||||
|
|
||||||
g_hash_table_iter_init (&iter2, all_refs);
|
g_hash_table_iter_init (&iter2, all_refs);
|
||||||
while (g_hash_table_iter_next (&iter2, &key, &value))
|
while (g_hash_table_iter_next (&iter2, &key, &value))
|
||||||
|
@ -1885,14 +1900,16 @@ xdg_app_repo_generate_appstream (OstreeRepo *repo,
|
||||||
if (strcmp (split[2], arch) != 0)
|
if (strcmp (split[2], arch) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!extract_appstream (repo, appstream_components, ref, split[1], tmpdir_file, cancellable, &my_error))
|
if (!extract_appstream (repo, appstream_root,
|
||||||
|
ref, split[1], tmpdir_file,
|
||||||
|
cancellable, &my_error))
|
||||||
{
|
{
|
||||||
g_print ("No appstream data for %s\n", ref);
|
g_print ("No appstream data for %s\n", ref);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xdg_app_xml_add (appstream_components, xdg_app_xml_new_text ("\n"));
|
xdg_app_xml_add (appstream_root->first_child, xdg_app_xml_new_text ("\n"));
|
||||||
|
|
||||||
xml = g_string_new ("");
|
xml = g_string_new ("");
|
||||||
xdg_app_xml_to_string (appstream_root, xml);
|
xdg_app_xml_to_string (appstream_root, xml);
|
||||||
|
|
|
@ -178,11 +178,6 @@ gboolean xdg_app_repo_update (OstreeRepo *repo,
|
||||||
const char *gpg_homedir,
|
const char *gpg_homedir,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
gboolean xdg_app_repo_generate_appstream (OstreeRepo *repo,
|
|
||||||
const char **gpg_key_ids,
|
|
||||||
const char *gpg_homedir,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
GVariant * xdg_app_bundle_load (GFile *file,
|
GVariant * xdg_app_bundle_load (GFile *file,
|
||||||
char **commit,
|
char **commit,
|
||||||
|
@ -293,4 +288,16 @@ XdgAppXml *xdg_app_xml_find (XdgAppXml *node,
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(XdgAppXml, xdg_app_xml_free);
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(XdgAppXml, xdg_app_xml_free);
|
||||||
|
|
||||||
|
|
||||||
|
XdgAppXml *xdg_app_appstream_xml_new (void);
|
||||||
|
gboolean xdg_app_appstream_xml_migrate (XdgAppXml *source,
|
||||||
|
XdgAppXml *dest,
|
||||||
|
const char *ref,
|
||||||
|
const char *id,
|
||||||
|
GKeyFile *metadata);
|
||||||
|
gboolean xdg_app_repo_generate_appstream (OstreeRepo *repo,
|
||||||
|
const char **gpg_key_ids,
|
||||||
|
const char *gpg_homedir,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
#endif /* __XDG_APP_UTILS_H__ */
|
#endif /* __XDG_APP_UTILS_H__ */
|
||||||
|
|
Loading…
Reference in New Issue