Skip to content

Commit

Permalink
Implement support for external release metadata
Browse files Browse the repository at this point in the history
Resolves: #436
  • Loading branch information
ximion committed Jan 16, 2023
1 parent 794182c commit ba8a511
Show file tree
Hide file tree
Showing 17 changed files with 783 additions and 36 deletions.
7 changes: 7 additions & 0 deletions compose/asc-compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,13 @@ asc_compose_process_task_cb (AscComposeTask *ctask, AscCompose *compose)
g_strdup (as_component_get_id (cpt)));
}

/* process any release information of this component and download release data if needed */
asc_process_metainfo_releases (ctask->result,
ctask->unit,
cpt,
mi_fname,
as_flags_contains (priv->flags, ASC_COMPOSE_FLAG_ALLOW_NET));

/* validate the data */
if (as_flags_contains (priv->flags, ASC_COMPOSE_FLAG_VALIDATE)) {
asc_validate_metainfo_data_for_component (ctask->result,
Expand Down
10 changes: 10 additions & 0 deletions compose/asc-hint-tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ AscHintTagStatic asc_hint_tag_list[] = {
"<code>type=</code> property of the component root-node in the MetaInfo XML file does not contain a spelling mistake."
},

{ "metainfo-releases-download-failed",
AS_ISSUE_SEVERITY_WARNING,
"Unable to download release information from <code>{{url}}</code>. The error message was: {{msg}}."
},

{ "metainfo-releases-read-failed",
AS_ISSUE_SEVERITY_ERROR,
"Unable to read release information from <code>{{path}}</code>. The error message was: {{msg}}."
},

{ "file-read-error",
AS_ISSUE_SEVERITY_ERROR,
"Unable to read data from file <code>{{fname}}</code>: {{msg}}",
Expand Down
83 changes: 74 additions & 9 deletions compose/asc-utils-metainfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ asc_parse_metainfo_data (AscResult *cres, AsMetadata *mdata, GBytes *bytes, cons
return NULL;
}

/* limit the amount of releases that we add to the output metadata.
* since releases are sorted with the newest one at the top, we will only
* remove the older ones. */
if (as_component_get_kind (cpt) != AS_COMPONENT_KIND_OPERATING_SYSTEM) {
GPtrArray *releases = as_component_get_releases (cpt);
if (releases->len > MAX_RELEASE_INFO_COUNT)
g_ptr_array_set_size (releases, MAX_RELEASE_INFO_COUNT);
}

return g_object_ref (cpt);
}

Expand Down Expand Up @@ -132,6 +123,80 @@ asc_parse_metainfo_data_simple (AscResult *cres, GBytes *bytes, const gchar *mi_
mi_basename);
}

/**
* asc_process_metainfo_releases:
* @cres: an #AscResult instance.
* @unit: an #AscUnit where release information could be read from.
* @cpt: the #AsComponent to read release data for.
* @mi_filename: the metadata filename for the component, as found in the passed unit.
* @allow_net: set to %TRUE if network access should be allowed.
*
* Reads an external release description file, either from a network location or from
* the given unit. Also performs further processing on the release information, like sorting
* releases or pruning old ones.
**/
void
asc_process_metainfo_releases (AscResult *cres, AscUnit *unit, AsComponent *cpt, const gchar *mi_filename, gboolean allow_net)
{
g_autoptr(GError) local_error = NULL;

/* download external release metadata or fetch local release data */
if (as_component_get_releases_kind (cpt) == AS_RELEASES_KIND_EXTERNAL) {
if (allow_net && as_component_get_releases_url (cpt) != NULL) {
/* get the release data from a network location */
if (!as_component_load_releases (cpt,
TRUE, /* reload */
TRUE, /* use network */
&local_error)) {
asc_result_add_hint (cres, NULL,
"metainfo-releases-download-failed",
"url", as_component_get_releases_url (cpt),
"msg", local_error->message,
NULL);
return;
}
} else {
/* we need to find local release information */
g_autofree gchar *relfile_path = NULL;
g_autofree gchar *relfile_name = NULL;
g_autofree gchar *tmp = NULL;
g_autoptr(GBytes) relmd_bytes = NULL;

relfile_name = g_strconcat (as_component_get_id (cpt), ".releases.xml", NULL);
tmp = g_path_get_dirname (mi_filename);
relfile_path = g_build_filename (tmp, "releases", relfile_name, NULL);

relmd_bytes = asc_unit_read_data (unit, relfile_path, &local_error);
if (relmd_bytes == NULL) {
asc_result_add_hint (cres, NULL,
"metainfo-releases-read-failed",
"path", relfile_path,
"msg", local_error->message,
NULL);
return;
}

if (!as_component_load_releases_from_bytes (cpt, relmd_bytes, &local_error)) {
asc_result_add_hint (cres, NULL,
"metainfo-releases-read-failed",
"path", relfile_path,
"msg", local_error->message,
NULL);
return;
}
}
}

/* limit the amount of releases that we add to the output metadata.
* since releases are sorted with the newest one at the top, we will only
* remove the older ones. */
if (as_component_get_kind (cpt) != AS_COMPONENT_KIND_OPERATING_SYSTEM) {
GPtrArray *releases = as_component_get_releases (cpt);
if (releases->len > MAX_RELEASE_INFO_COUNT)
g_ptr_array_set_size (releases, MAX_RELEASE_INFO_COUNT);
}
}

/**
* asc_validate_metainfo_data_for_component:
* @cres: an #AscResult instance.
Expand Down
5 changes: 5 additions & 0 deletions compose/asc-utils-metainfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ AsComponent *asc_parse_metainfo_data (AscResult *cres,
AsComponent *asc_parse_metainfo_data_simple (AscResult *cres,
GBytes *bytes,
const gchar *mi_basename);
void asc_process_metainfo_releases (AscResult *cres,
AscUnit *unit,
AsComponent *cpt,
const gchar *mi_filename,
gboolean allow_net);

void asc_validate_metainfo_data_for_component (AscResult *cres,
AsValidator *validator,
Expand Down
3 changes: 3 additions & 0 deletions src/as-component-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ void as_component_complete (AsComponent *cpt,
gchar *scr_base_url,
GPtrArray *icon_paths);

gint as_component_releases_compare (gconstpointer a,
gconstpointer b);

AS_INTERNAL_VISIBLE
GHashTable *as_component_get_languages_table (AsComponent *cpt);

Expand Down
Loading

0 comments on commit ba8a511

Please sign in to comment.