[gnome-software: 1/2] gs-appstream: Add support for `date` attribute in release nodes
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 1/2] gs-appstream: Add support for `date` attribute in release nodes
- Date: Tue, 9 Mar 2021 10:22:35 +0000 (UTC)
commit 5ef7ce90b374afb622ab7cb9caa4caad0b2c0795
Author: Philip Withnall <pwithnall endlessos org>
Date: Fri Mar 5 19:49:24 2021 +0000
gs-appstream: Add support for `date` attribute in release nodes
Previously we only supported the `timestamp` attribute, but the spec
requires support for both:
https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-releases
Investigated and solved by Phaedrus Leeds.
This fixes the date not appearing for some software releases in the
version history widget.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Fixes: #1145
plugins/core/gs-appstream.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 062761623..69dccef30 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -413,6 +413,29 @@ gs_appstream_refine_add_provides (GsApp *app, XbNode *component, GError **error)
return TRUE;
}
+static guint64
+component_get_release_timestamp (XbNode *component)
+{
+ guint64 timestamp;
+ const gchar *date_str;
+
+ /* Spec says to prefer `timestamp` over `date` if both are provided:
+ * https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-releases */
+ timestamp = xb_node_query_attr_as_uint (component, "releases/release", "timestamp", NULL);
+ date_str = xb_node_query_attr (component, "releases/release", "date", NULL);
+
+ if (timestamp != G_MAXUINT64) {
+ return timestamp;
+ } else if (date_str != NULL) {
+ g_autoptr(GDateTime) date = g_date_time_new_from_iso8601 (date_str, NULL);
+ if (date != NULL)
+ return g_date_time_to_unix (date);
+ }
+
+ /* Unknown. */
+ return G_MAXUINT64;
+}
+
static gboolean
gs_appstream_is_recent_release (XbNode *component)
{
@@ -420,7 +443,7 @@ gs_appstream_is_recent_release (XbNode *component)
gint64 secs;
/* get newest release */
- ts = xb_node_query_attr_as_uint (component, "releases/release", "timestamp", NULL);
+ ts = component_get_release_timestamp (component);
if (ts == G_MAXUINT64)
return FALSE;
@@ -608,6 +631,7 @@ gs_appstream_refine_add_version_history (GsApp *app, XbNode *component, GError *
g_autoptr(XbNode) description_node = NULL;
g_autofree gchar *description = NULL;
guint64 timestamp;
+ const gchar *date_str;
g_autoptr(AsRelease) release = NULL;
g_autofree char *timestamp_xpath = NULL;
@@ -617,6 +641,7 @@ gs_appstream_refine_add_version_history (GsApp *app, XbNode *component, GError *
timestamp_xpath = g_strdup_printf ("releases/release[%u]", i+1);
timestamp = xb_node_query_attr_as_uint (component, timestamp_xpath, "timestamp", NULL);
+ date_str = xb_node_query_attr (component, timestamp_xpath, "date", NULL);
/* include updates with or without a description */
description_node = xb_node_query_first (release_node, "description", NULL);
@@ -627,6 +652,8 @@ gs_appstream_refine_add_version_history (GsApp *app, XbNode *component, GError *
as_release_set_version (release, version);
if (timestamp != G_MAXUINT64)
as_release_set_timestamp (release, timestamp);
+ else if (date_str != NULL) /* timestamp takes precedence over date */
+ as_release_set_date (release, date_str);
if (description != NULL)
as_release_set_description (release, description, NULL);
@@ -972,7 +999,7 @@ gs_appstream_refine_app (GsPlugin *plugin,
}
/* set the release date */
- timestamp = xb_node_query_attr_as_uint (component, "releases/release", "timestamp", NULL);
+ timestamp = component_get_release_timestamp (component);
if (timestamp != G_MAXUINT64)
gs_app_set_release_date (app, timestamp);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]