From ce8cfd42d196a09babce9126cf6ea9aa92edaabc Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 18 Jul 2020 22:53:16 +0200 Subject: [PATCH] validate: Make missing more obvious MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, when was not contained in , the following confusing error message was printed: • tag-missing : required Now, the validation will print • tag-missing : required when is missing altogether and • tag-missing : required in when the tag does not contain any . --- libappstream-glib/as-app-private.h | 2 ++ libappstream-glib/as-app-validate.c | 7 ++++--- libappstream-glib/as-app.c | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libappstream-glib/as-app-private.h b/libappstream-glib/as-app-private.h index 5089ba88..8e501f97 100644 --- a/libappstream-glib/as-app-private.h +++ b/libappstream-glib/as-app-private.h @@ -43,6 +43,7 @@ G_BEGIN_DECLS * @AS_APP_PROBLEM_DUPLICATE_SCREENSHOT: More than one screenshot with the same URL * @AS_APP_PROBLEM_DUPLICATE_CONTENT_RATING: More than one content rating with the same kind * @AS_APP_PROBLEM_DUPLICATE_AGREEMENT: More than one agreement with the same kind + * @AS_APP_PROBLEM_MISSING_RELEASES_TAG: The file lacks tag * * The application problems detected when loading. **/ @@ -69,6 +70,7 @@ typedef enum { AS_APP_PROBLEM_DUPLICATE_SCREENSHOT = 1 << 18, AS_APP_PROBLEM_DUPLICATE_CONTENT_RATING = 1 << 19, AS_APP_PROBLEM_DUPLICATE_AGREEMENT = 1 << 20, + AS_APP_PROBLEM_MISSING_RELEASES_TAG = 1 << 21, /*< private >*/ AS_APP_PROBLEM_LAST } AsAppProblems; diff --git a/libappstream-glib/as-app-validate.c b/libappstream-glib/as-app-validate.c index 60b46e53..7b036c6b 100644 --- a/libappstream-glib/as-app-validate.c +++ b/libappstream-glib/as-app-validate.c @@ -932,7 +932,7 @@ as_app_validate_kudos (AsApp *app, AsAppValidateHelper *helper, GError **error) } static gboolean -as_app_validate_releases (AsApp *app, AsAppValidateHelper *helper, GError **error) +as_app_validate_releases (AsApp *app, AsAppProblems problems, AsAppValidateHelper *helper, GError **error) { GPtrArray *releases; AsFormat *format; @@ -958,7 +958,8 @@ as_app_validate_releases (AsApp *app, AsAppValidateHelper *helper, GError **erro if (require_release && releases->len == 0) { ai_app_validate_add (helper, AS_PROBLEM_KIND_TAG_MISSING, - " required"); + (problems & AS_APP_PROBLEM_MISSING_RELEASES_TAG) > 0 ? + " required" : " required in "); return TRUE; } for (guint i = 0; i < releases->len; i++) { @@ -1623,7 +1624,7 @@ as_app_validate (AsApp *app, guint32 flags, GError **error) as_app_validate_launchables (app, helper); /* releases */ - if (!as_app_validate_releases (app, helper, error)) + if (!as_app_validate_releases (app, problems, helper, error)) return NULL; /* kudos */ diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index f5c8614c..176cca84 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -477,6 +477,7 @@ as_app_init (AsApp *app) { AsAppPrivate *priv = GET_PRIVATE (app); g_mutex_init (&priv->unique_id_mutex); + priv->problems = AS_APP_PROBLEM_MISSING_RELEASES_TAG; priv->categories = g_ptr_array_new_with_free_func ((GDestroyNotify) as_ref_string_unref); priv->compulsory_for_desktops = g_ptr_array_new_with_free_func ((GDestroyNotify) as_ref_string_unref); priv->content_ratings = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); @@ -5275,6 +5276,7 @@ as_app_node_parse_child (AsApp *app, GNode *n, guint32 flags, /* */ case AS_TAG_RELEASES: + priv->problems &= ~AS_APP_PROBLEM_MISSING_RELEASES_TAG; if (!(flags & AS_APP_PARSE_FLAG_APPEND_DATA)) g_ptr_array_set_size (priv->releases, 0); for (c = n->children; c != NULL; c = c->next) {