diff options
author | Corentin Noël <corentin.noel@collabora.com> | 2021-08-02 16:49:27 +0200 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2021-08-03 08:20:30 +0100 |
commit | b2fafbca02219748fd84e3b96f1419030fd5c466 (patch) | |
tree | 8c3aab7f661958630cf8050d23b2af9197241e98 /libappstream-glib | |
parent | 60e85d47255a5a4423f4411532ff16554470a4dc (diff) | |
download | appstream-glib-b2fafbca02219748fd84e3b96f1419030fd5c466.tar.gz |
Consider AppStream version as a string
Always store the AppStream metadata version as a string and compare it
like any other version.
This allows to have 0.10 > 0.8 for instance.
Diffstat (limited to 'libappstream-glib')
-rw-r--r-- | libappstream-glib/as-app.c | 4 | ||||
-rw-r--r-- | libappstream-glib/as-node-private.h | 4 | ||||
-rw-r--r-- | libappstream-glib/as-node.c | 22 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 48 | ||||
-rw-r--r-- | libappstream-glib/as-store.c | 117 | ||||
-rw-r--r-- | libappstream-glib/as-store.h | 3 |
6 files changed, 125 insertions, 73 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index 3939970..b65f08d 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -4831,7 +4831,7 @@ as_app_node_insert (AsApp *app, GNode *parent, AsNodeContext *ctx) /* <custom> or <metadata> */ if (g_hash_table_size (priv->metadata) > 0) { - tmp = as_node_context_get_version (ctx) > 0.9 ? "custom" : "metadata"; + tmp = as_utils_vercmp (as_node_context_get_version (ctx), "0.9") > 0 ? "custom" : "metadata"; node_tmp = as_node_insert (node_app, tmp, NULL, 0, NULL); as_node_insert_hash (node_tmp, "value", "key", priv->metadata, FALSE); } @@ -6463,7 +6463,7 @@ as_app_to_xml (AsApp *app, GError **error) { g_autoptr(AsNodeContext) ctx = as_node_context_new (); g_autoptr(AsNode) root = as_node_new (); - as_node_context_set_version (ctx, 1.0); + as_node_context_set_version (ctx, "1.0"); as_node_context_set_output (ctx, AS_FORMAT_KIND_APPDATA); as_app_node_insert (app, root, ctx); return as_node_to_xml (root, diff --git a/libappstream-glib/as-node-private.h b/libappstream-glib/as-node-private.h index ed25c8d..467011b 100644 --- a/libappstream-glib/as-node-private.h +++ b/libappstream-glib/as-node-private.h @@ -20,9 +20,9 @@ G_BEGIN_DECLS typedef struct _AsNodeContext AsNodeContext; AsNodeContext *as_node_context_new (void); void as_node_context_free (AsNodeContext *ctx); -gdouble as_node_context_get_version (AsNodeContext *ctx); +const gchar *as_node_context_get_version (AsNodeContext *ctx); void as_node_context_set_version (AsNodeContext *ctx, - gdouble version); + const gchar *version); AsFormatKind as_node_context_get_format_kind (AsNodeContext *ctx); void as_node_context_set_format_kind (AsNodeContext *ctx, AsFormatKind format_kind); diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c index b4159ea..4d438f5 100644 --- a/libappstream-glib/as-node.c +++ b/libappstream-glib/as-node.c @@ -2166,7 +2166,7 @@ as_node_get_localized_unwrap (const AsNode *node, GError **error) struct _AsNodeContext { AsFormatKind format_kind; AsFormatKind output; - gdouble version; + gchar *version; gboolean output_trusted; AsRefString *media_base_url; }; @@ -2185,7 +2185,7 @@ as_node_context_new (void) { AsNodeContext *ctx; ctx = g_new0 (AsNodeContext, 1); - ctx->version = 0.f; + ctx->version = g_strdup ("0.0"); ctx->format_kind = AS_FORMAT_KIND_APPSTREAM; ctx->output = AS_FORMAT_KIND_UNKNOWN; return ctx; @@ -2206,6 +2206,7 @@ as_node_context_free (AsNodeContext *ctx) return; if (ctx->media_base_url != NULL) as_ref_string_unref (ctx->media_base_url); + g_clear_pointer (&ctx->version, g_free); g_free (ctx); } @@ -2215,11 +2216,11 @@ as_node_context_free (AsNodeContext *ctx) * * Gets the AppStream API version used when parsing or inserting nodes. * - * Returns: version number + * Returns: the API version * - * Since: 0.3.6 + * Since: 0.7.19 **/ -gdouble +const gchar * as_node_context_get_version (AsNodeContext *ctx) { return ctx->version; @@ -2228,16 +2229,19 @@ as_node_context_get_version (AsNodeContext *ctx) /** * as_node_context_set_version: (skip) * @ctx: a #AsNodeContext. - * @version: an API version number to target. + * @version: an API version to target. * * Sets the AppStream API version used when parsing or inserting nodes. * - * Since: 0.3.6 + * Since: 0.7.19 **/ void -as_node_context_set_version (AsNodeContext *ctx, gdouble version) +as_node_context_set_version (AsNodeContext *ctx, const gchar *version) { - ctx->version = version; + if (g_strcmp0 (ctx->version, version) != 0) { + g_free (ctx->version); + ctx->version = g_strdup (version); + } } /** diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index eafb15e..efcaa1f 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -533,7 +533,7 @@ as_test_release_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_release_node_insert (release, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); ret = as_test_compare_lines (xml->str, src, &error); @@ -604,7 +604,7 @@ as_test_provide_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_provide_node_insert (provide, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); ret = as_test_compare_lines (xml->str, src, &error); @@ -646,7 +646,7 @@ as_test_launchable_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_launchable_node_insert (launchable, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); ret = as_test_compare_lines (xml->str, src, &error); @@ -737,7 +737,7 @@ as_test_release_appstream_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 1.0); + as_node_context_set_version (ctx, "1.0"); as_node_context_set_format_kind (ctx, AS_FORMAT_KIND_APPSTREAM); n = as_release_node_insert (release, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); @@ -1021,7 +1021,7 @@ as_test_icon_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_icon_node_insert (icon, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); ret = as_test_compare_lines (xml->str, "<icon type=\"cached\" height=\"64\" width=\"64\">app.png</icon>", &error); @@ -1084,7 +1084,7 @@ as_test_icon_scale_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.9); + as_node_context_set_version (ctx, "0.9"); n = as_icon_node_insert (icon, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1136,7 +1136,7 @@ as_test_checksum_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_checksum_node_insert (csum, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1230,7 +1230,7 @@ as_test_icon_embedded_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_icon_node_insert (icon, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1291,7 +1291,7 @@ as_test_image_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_image_node_insert (image, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1369,7 +1369,7 @@ as_test_agreement_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_agreement_node_insert (agreement, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1431,7 +1431,7 @@ as_test_review_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_review_node_insert (review, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1497,7 +1497,7 @@ as_test_require_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_app_node_insert (app, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1577,7 +1577,7 @@ as_test_suggest_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_suggest_node_insert (suggest, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1622,7 +1622,7 @@ as_test_bundle_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_bundle_node_insert (bundle, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1665,7 +1665,7 @@ as_test_translation_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_translation_node_insert (translation, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1728,7 +1728,7 @@ as_test_screenshot_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.8); + as_node_context_set_version (ctx, "0.8"); n = as_screenshot_node_insert (screenshot, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); ret = as_test_compare_lines (xml->str, src, &error); @@ -1794,7 +1794,7 @@ as_test_content_rating_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.8); + as_node_context_set_version (ctx, "0.8"); n = as_content_rating_node_insert (content_rating, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); ret = as_test_compare_lines (xml->str, src, &error); @@ -2120,7 +2120,7 @@ as_test_app_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 1.0); + as_node_context_set_version (ctx, "1.0"); n = as_app_node_insert (app, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); ret = as_test_compare_lines (xml->str, src, &error); @@ -2750,7 +2750,7 @@ as_test_app_no_markup_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_app_node_insert (app, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); ret = as_test_compare_lines (xml->str, src, &error); @@ -3767,7 +3767,7 @@ as_test_store_demote_func (void) /* add apps */ store = as_store_new (); - as_store_set_api_version (store, 0.8); + as_store_set_version (store, "0.8"); as_store_add_app (store, app_desktop); as_store_add_app (store, app_appdata); @@ -3950,7 +3950,7 @@ as_test_store_func (void) g_assert_cmpstr (as_store_get_origin (store), ==, NULL); /* check string output */ - as_store_set_api_version (store, 0.6); + as_store_set_version (store, "0.6"); xml = as_store_to_xml (store, 0); ret = as_test_compare_lines (xml->str, "<components version=\"0.6\">" @@ -3972,7 +3972,7 @@ as_test_store_func (void) as_store_remove_app (store, app); /* check string output */ - as_store_set_api_version (store, 0.6); + as_store_set_version (store, "0.6"); xml = as_store_to_xml (store, 0); ret = as_test_compare_lines (xml->str, "<components version=\"0.6\">" @@ -4159,7 +4159,7 @@ as_test_store_versions_func (void) g_assert (as_app_get_format_by_kind (app, AS_FORMAT_KIND_APPSTREAM) != NULL); /* test with latest features */ - as_store_set_api_version (store, 0.6); + as_store_set_version (store, "0.6"); g_assert_cmpfloat (as_store_get_api_version (store), <, 0.6 + 0.01); g_assert_cmpfloat (as_store_get_api_version (store), >, 0.6 - 0.01); xml = as_store_to_xml (store, AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); @@ -4323,7 +4323,7 @@ as_test_node_no_dup_c_func (void) /* back to node */ root = as_node_new (); - as_node_context_set_version (ctx, 0.4); + as_node_context_set_version (ctx, "0.4"); n = as_app_node_insert (app, root, ctx); xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); g_assert_cmpstr (xml->str, ==, diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c index 9595f29..65b557c 100644 --- a/libappstream-glib/as-store.c +++ b/libappstream-glib/as-store.c @@ -35,7 +35,7 @@ #include "as-yaml.h" #include "as-store-cab.h" -#define AS_API_VERSION_NEWEST 0.14 +#define AS_API_VERSION_NEWEST "0.14" typedef enum { AS_STORE_PROBLEM_NONE = 0, @@ -48,7 +48,7 @@ typedef struct gchar *destdir; gchar *origin; gchar *builder_id; - gdouble api_version; + gchar *api_version; GPtrArray *array; /* of AsApp */ GHashTable *hash_id; /* of GPtrArray of AsApp{id} */ GHashTable *hash_merge_id; /* of GPtrArray of AsApp{id} */ @@ -116,6 +116,7 @@ as_store_finalize (GObject *object) g_free (priv->destdir); g_free (priv->origin); g_free (priv->builder_id); + g_free (priv->api_version); g_ptr_array_unref (priv->array); g_object_unref (priv->monitor); g_object_unref (priv->profile); @@ -1667,7 +1668,7 @@ as_store_from_root (AsStore *store, /* get version */ tmp = as_node_get_attribute (apps, "version"); if (tmp != NULL) - priv->api_version = g_ascii_strtod (tmp, NULL); + priv->api_version = g_strdup (tmp); /* set in the XML file */ tmp = as_node_get_attribute (apps, "origin"); @@ -1867,7 +1868,7 @@ load_yaml (AsStore *store, } if (g_strcmp0 (tmp, "Version") == 0) { if (as_yaml_node_get_value (n) != NULL) - as_store_set_api_version (store, g_ascii_strtod (as_yaml_node_get_value (n), NULL)); + as_store_set_version (store, as_yaml_node_get_value (n)); continue; } if (g_strcmp0 (tmp, "MediaBaseUrl") == 0) { @@ -2487,7 +2488,6 @@ as_store_to_xml (AsStore *store, guint32 flags) GString *xml; gboolean output_trusted = FALSE; guint i; - gchar version[6]; g_autoptr(AsNodeContext) ctx = NULL; g_return_val_if_fail (AS_IS_STORE (store), NULL); @@ -2508,10 +2508,8 @@ as_store_to_xml (AsStore *store, guint32 flags) as_node_add_attribute (node_apps, "builder_id", priv->builder_id); /* set version attribute */ - if (priv->api_version > 0.1f) { - g_ascii_formatd (version, sizeof (version), - "%.1f", priv->api_version); - as_node_add_attribute (node_apps, "version", version); + if (as_utils_vercmp (priv->api_version, "0.1") > 0) { + as_node_add_attribute (node_apps, "version", priv->api_version); } /* output is trusted, so include update_contact */ @@ -2782,16 +2780,17 @@ as_store_get_destdir (AsStore *store) * * Gets the AppStream API version. * - * Returns: the #AsNodeInsertFlags, or 0 if unset + * Returns: the API version * * Since: 0.1.1 + * Deprecated: 0.7.19: Use as_store_get_version() instead. **/ gdouble as_store_get_api_version (AsStore *store) { AsStorePrivate *priv = GET_PRIVATE (store); g_return_val_if_fail (AS_IS_STORE (store), 0.0); - return priv->api_version; + return g_strtod (priv->api_version, NULL); } /** @@ -2802,13 +2801,59 @@ as_store_get_api_version (AsStore *store) * Sets the AppStream API version. * * Since: 0.1.1 + * Deprecated: 0.7.19: Use as_store_set_version() instead. **/ void as_store_set_api_version (AsStore *store, gdouble api_version) { + gchar version[6]; + + g_return_if_fail (AS_IS_STORE (store)); + + g_ascii_formatd (version, sizeof (version), "%.1f", api_version); + as_store_set_version (store, version); +} + +/** + * as_store_get_version: + * @store: a #AsStore instance. + * + * Gets the AppStream API version. + * + * Returns: the API version + * + * Since: 0.7.19 + **/ +const gchar * +as_store_get_version (AsStore *store) +{ AsStorePrivate *priv = GET_PRIVATE (store); + + g_return_val_if_fail (AS_IS_STORE (store), "0.0"); + + return priv->api_version; +} + +/** + * as_store_set_version: + * @store: a #AsStore instance. + * @api_version: the API version + * + * Sets the AppStream API version. + * + * Since: 0.7.19 + **/ +void +as_store_set_version (AsStore *store, const gchar *api_version) +{ + AsStorePrivate *priv = GET_PRIVATE (store); + g_return_if_fail (AS_IS_STORE (store)); - priv->api_version = api_version; + + if (g_strcmp0 (priv->api_version, api_version) != 0) { + g_free (priv->api_version); + priv->api_version = g_strdup (api_version); + } } /** @@ -3667,11 +3712,11 @@ as_store_validate (AsStore *store, guint32 flags, GError **error) probs = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); /* check the root node */ - if (priv->api_version < 0.6) { + if (as_utils_vercmp (priv->api_version, "0.6") < 0) { if ((priv->problems & AS_STORE_PROBLEM_LEGACY_ROOT) == 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "XML root is not <applications>", priv->api_version); } @@ -3679,14 +3724,14 @@ as_store_validate (AsStore *store, guint32 flags, GError **error) if ((priv->problems & AS_STORE_PROBLEM_LEGACY_ROOT) != 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "XML root is not <components>", priv->api_version); } if (priv->origin == NULL) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_MISSING, - "metadata version is v%.1f and " + "metadata version is v%s and " "origin attribute is missing", priv->api_version); } @@ -3706,64 +3751,64 @@ as_store_validate (AsStore *store, guint32 flags, GError **error) g_autoptr(GPtrArray) probs_app = NULL; app = g_ptr_array_index (apps, i); - if (priv->api_version < 0.3) { + if (as_utils_vercmp (priv->api_version, "0.3") < 0) { if (as_app_get_source_pkgname (app) != NULL) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<source_pkgname> only introduced in v0.3", priv->api_version); } if (as_app_get_priority (app) != 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<priority> only introduced in v0.3", priv->api_version); } } - if (priv->api_version < 0.4) { + if (as_utils_vercmp (priv->api_version, "0.4") < 0) { if (as_app_get_project_group (app) != NULL) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<project_group> only introduced in v0.4", priv->api_version); } if (as_app_get_mimetypes(app)->len > 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<mimetypes> only introduced in v0.4", priv->api_version); } if (as_app_get_screenshots(app)->len > 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<screenshots> only introduced in v0.4", priv->api_version); } if (as_app_get_compulsory_for_desktops(app)->len > 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<compulsory_for_desktop> only introduced in v0.4", priv->api_version); } if (g_list_length (as_app_get_languages(app)) > 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<languages> only introduced in v0.4", priv->api_version); } } - if (priv->api_version < 0.6) { + if (as_utils_vercmp (priv->api_version, "0.6") < 0) { if ((as_app_get_problems (app) & AS_APP_PROBLEM_PREFORMATTED_DESCRIPTION) == 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<description> markup " "was introduced in v0.6", priv->api_version); @@ -3771,21 +3816,21 @@ as_store_validate (AsStore *store, guint32 flags, GError **error) if (as_app_get_architectures(app)->len > 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<architectures> only introduced in v0.6", priv->api_version); } if (as_app_get_releases(app)->len > 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<releases> only introduced in v0.6", priv->api_version); } if (as_app_get_provides(app)->len > 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<provides> only introduced in v0.6", priv->api_version); } @@ -3793,32 +3838,32 @@ as_store_validate (AsStore *store, guint32 flags, GError **error) if ((as_app_get_problems (app) & AS_APP_PROBLEM_PREFORMATTED_DESCRIPTION) != 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "%s: metadata version is v%.1f and " + "%s: metadata version is v%s and " "<description> requiring markup " "was introduced in v0.6", as_app_get_id (app), priv->api_version); } } - if (priv->api_version < 0.7) { + if (as_utils_vercmp (priv->api_version, "0.7") < 0) { if (as_app_get_kind (app) == AS_APP_KIND_ADDON) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "addon kinds only introduced in v0.7", priv->api_version); } if (as_app_get_developer_name (app, NULL) != NULL) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<developer_name> only introduced in v0.7", priv->api_version); } if (as_app_get_extends(app)->len > 0) { as_store_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, - "metadata version is v%.1f and " + "metadata version is v%s and " "<extends> only introduced in v0.7", priv->api_version); } @@ -3959,7 +4004,7 @@ as_store_init (AsStore *store) g_mutex_init (&priv->mutex); priv->profile = as_profile_new (); priv->stemmer = as_stemmer_new (); - priv->api_version = AS_API_VERSION_NEWEST; + priv->api_version = g_strdup (AS_API_VERSION_NEWEST); priv->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); priv->watch_flags = AS_STORE_WATCH_FLAG_NONE; priv->search_match = AS_APP_SEARCH_MATCH_LAST; diff --git a/libappstream-glib/as-store.h b/libappstream-glib/as-store.h index e775c71..bfd1605 100644 --- a/libappstream-glib/as-store.h +++ b/libappstream-glib/as-store.h @@ -258,6 +258,9 @@ void as_store_set_destdir (AsStore *store, gdouble as_store_get_api_version (AsStore *store); void as_store_set_api_version (AsStore *store, gdouble api_version); +const gchar *as_store_get_version (AsStore *store); +void as_store_set_version (AsStore *store, + const gchar *api_version); guint32 as_store_get_add_flags (AsStore *store); void as_store_set_add_flags (AsStore *store, guint32 add_flags); |