Skip to content

Commit

Permalink
validate: Make missing <releases> more obvious
Browse files Browse the repository at this point in the history
Previously, when <release> was not contained in <releases>, the following confusing
error message was printed:

    • tag-missing           : <release> required

Now, the validation will print

    • tag-missing           : <releases> required

when <releases> is missing altogether and

    • tag-missing           : <release> required in <releases>

when the <releases> tag does not contain any <release>.
  • Loading branch information
jtojnar committed Jul 18, 2020
1 parent 2b4f436 commit ce8cfd4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions libappstream-glib/as-app-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <releases> tag
*
* The application problems detected when loading.
**/
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions libappstream-glib/as-app-validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
"<release> required");
(problems & AS_APP_PROBLEM_MISSING_RELEASES_TAG) > 0 ?
"<releases> required" : "<release> required in <releases>");
return TRUE;
}
for (guint i = 0; i < releases->len; i++) {
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions libappstream-glib/as-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -5275,6 +5276,7 @@ as_app_node_parse_child (AsApp *app, GNode *n, guint32 flags,

/* <releases> */
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) {
Expand Down

0 comments on commit ce8cfd4

Please sign in to comment.