diff options
author | Richard Hughes <richard@hughsie.com> | 2017-08-03 11:30:09 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2017-08-03 11:30:15 +0100 |
commit | a4d48560ed27a6cd3f19b6082f4f4a22a63b9b65 (patch) | |
tree | 9afd81b7967e20f64782fcd0c74b2db24b672853 | |
parent | 17fb0e8a65ad03083a29a491b05a01d09da9895b (diff) | |
download | appstream-glib-a4d48560ed27a6cd3f19b6082f4f4a22a63b9b65.tar.gz |
Fail to validate if AppData screenshots are duplicated
As as_app_parse_file() uses %AS_APP_TRUST_FLAG_CHECK_DUPLICATES our existing
validation rule checker to work. Add this to the AsAppProblems bitfield and
check this for a validation failure.
Now:
• tag-invalid : <screenshot> content was duplicated
Fixes: https://github.com/hughsie/appstream-glib/issues/185
-rw-r--r-- | libappstream-glib/as-app-private.h | 2 | ||||
-rw-r--r-- | libappstream-glib/as-app-validate.c | 5 | ||||
-rw-r--r-- | libappstream-glib/as-app.c | 4 |
3 files changed, 10 insertions, 1 deletions
diff --git a/libappstream-glib/as-app-private.h b/libappstream-glib/as-app-private.h index c4c6cb5..a36fd7c 100644 --- a/libappstream-glib/as-app-private.h +++ b/libappstream-glib/as-app-private.h @@ -55,6 +55,7 @@ G_BEGIN_DECLS * @AS_APP_PROBLEM_EXPECTED_CHILDREN: Children tags expected * @AS_APP_PROBLEM_INVALID_KEYWORDS: One or more keywords was invalid * @AS_APP_PROBLEM_DUPLICATE_RELEASE: More than one release with the same version + * @AS_APP_PROBLEM_DUPLICATE_SCREENSHOT: More than one screenshot with the same URL * * The application problems detected when loading. **/ @@ -78,6 +79,7 @@ typedef enum { AS_APP_PROBLEM_EXPECTED_CHILDREN = 1 << 15, AS_APP_PROBLEM_INVALID_KEYWORDS = 1 << 16, AS_APP_PROBLEM_DUPLICATE_RELEASE = 1 << 17, + AS_APP_PROBLEM_DUPLICATE_SCREENSHOT = 1 << 18, /*< private >*/ AS_APP_PROBLEM_LAST } AsAppProblems; diff --git a/libappstream-glib/as-app-validate.c b/libappstream-glib/as-app-validate.c index 8cdf1df..7e86ff8 100644 --- a/libappstream-glib/as-app-validate.c +++ b/libappstream-glib/as-app-validate.c @@ -1450,6 +1450,11 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error) AS_PROBLEM_KIND_TAG_INVALID, "<release> version was duplicated"); } + if (problems & AS_APP_PROBLEM_DUPLICATE_SCREENSHOT) { + ai_app_validate_add (helper, + AS_PROBLEM_KIND_TAG_INVALID, + "<screenshot> content was duplicated"); + } /* check for things that have to exist */ if (as_app_get_id (app) == NULL) { diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index fe0e310..5ad365a 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -3269,8 +3269,10 @@ as_app_add_screenshot (AsApp *app, AsScreenshot *screenshot) if ((priv->trust_flags & AS_APP_TRUST_FLAG_CHECK_DUPLICATES) > 0) { for (i = 0; i < priv->screenshots->len; i++) { ss = g_ptr_array_index (priv->screenshots, i); - if (as_screenshot_equal (ss, screenshot)) + if (as_screenshot_equal (ss, screenshot)) { + priv->problems |= AS_APP_PROBLEM_DUPLICATE_SCREENSHOT; return; + } } } |