diff options
author | Richard Hughes <richard@hughsie.com> | 2014-08-05 22:28:38 +0200 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-08-05 22:29:17 +0200 |
commit | 57991f9048319718c651d936e80d1003ed8d335f (patch) | |
tree | 30448f18fdccc8e12a6d5a63409fbbe744d811d3 | |
parent | a2663f6aaef204d9ec887dc97dbd82f03738c5ed (diff) | |
download | appstream-glib-57991f9048319718c651d936e80d1003ed8d335f.tar.gz |
Markup errors should not be fatal when assembling a store
If there's a single AppData file with invalid markup, do not fail to add all
applications to the store and instead just show a warning.
This fixes some odd behaviour in gnome-software on Fedora 21 when old versions
of the transmageddon package are also installed.
-rw-r--r-- | data/tests/Makefile.am | 1 | ||||
-rw-r--r-- | data/tests/usr/share/appdata/broken.appdata.xml | 7 | ||||
-rw-r--r-- | libappstream-glib/as-app.c | 18 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 31 | ||||
-rw-r--r-- | po/POTFILES.skip | 1 |
5 files changed, 56 insertions, 2 deletions
diff --git a/data/tests/Makefile.am b/data/tests/Makefile.am index b2f30cf..281e73f 100644 --- a/data/tests/Makefile.am +++ b/data/tests/Makefile.am @@ -15,6 +15,7 @@ test_files = \ ss-small.png \ success.appdata.xml \ translated.appdata.xml \ + usr/share/appdata/broken.appdata.xml \ usr/share/app-install/desktop/test.desktop \ usr/share/app-install/icons/test.png \ validate.xml.gz diff --git a/data/tests/usr/share/appdata/broken.appdata.xml b/data/tests/usr/share/appdata/broken.appdata.xml new file mode 100644 index 0000000..2807e0f --- /dev/null +++ b/data/tests/usr/share/appdata/broken.appdata.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Copyright (C) 2014 Richard Hughes <richard@hughsie.com> --> +<application> + <id type="desktop">broken.desktop</id> + <name>Broken</name> + <description><_p>tag is broken.</_p></description> +</application> diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index 88a194b..5d06c8d 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -2874,10 +2874,24 @@ as_app_node_parse_child (AsApp *app, GNode *n, AsAppParseFlags flags, GError **e /* unwrap appdata inline */ if (priv->source_kind == AS_APP_SOURCE_KIND_APPDATA) { + GError *error_local = NULL; _cleanup_hashtable_unref_ GHashTable *unwrapped; - unwrapped = as_node_get_localized_unwrap (n, error); - if (unwrapped == NULL) + unwrapped = as_node_get_localized_unwrap (n, &error_local); + if (unwrapped == NULL) { + if (g_error_matches (error_local, + AS_NODE_ERROR, + AS_NODE_ERROR_INVALID_MARKUP)) { + _cleanup_string_free_ GString *debug = NULL; + debug = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE); + g_warning ("ignoring description '%s' from %s: %s", + debug->str, + as_app_get_source_file (app), + error_local->message); + break; + } + g_propagate_error (error, error_local); return FALSE; + } as_app_subsume_dict (priv->descriptions, unwrapped, FALSE); break; } diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index de8c087..12061b9 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -920,6 +920,36 @@ as_test_store_local_app_install_func (void) } static void +as_test_store_local_appdata_func (void) +{ + AsApp *app; + GError *error = NULL; + gboolean ret; + _cleanup_free_ gchar *filename = NULL; + _cleanup_object_unref_ AsStore *store = NULL; + + /* this are the warnings expected */ + g_test_expect_message (G_LOG_DOMAIN, + G_LOG_LEVEL_WARNING, + "ignoring description '*' from */broken.appdata.xml: Unknown tag '_p'"); + + /* open test store */ + store = as_store_new (); + filename = as_test_get_filename ("."); + as_store_set_destdir (store, filename); + ret = as_store_load (store, AS_STORE_LOAD_FLAG_APPDATA, NULL, &error); + g_assert_no_error (error); + g_assert (ret); + g_assert_cmpint (as_store_get_size (store), ==, 1); + + /* make sure app is valid */ + app = as_store_get_app_by_id (store, "broken.desktop"); + g_assert (app != NULL); + g_assert_cmpstr (as_app_get_name (app, "C"), ==, "Broken"); + g_assert_cmpint (as_app_get_source_kind (app), ==, AS_APP_SOURCE_KIND_APPDATA); +} + +static void as_test_store_validate_func (void) { GError *error = NULL; @@ -2225,6 +2255,7 @@ main (int argc, char **argv) g_test_add_func ("/AppStream/store{metadata}", as_test_store_metadata_func); g_test_add_func ("/AppStream/store{validate}", as_test_store_validate_func); g_test_add_func ("/AppStream/store{local-app-install}", as_test_store_local_app_install_func); + g_test_add_func ("/AppStream/store{local-appdata}", as_test_store_local_appdata_func); g_test_add_func ("/AppStream/store{speed-appstream}", as_test_store_speed_appstream_func); g_test_add_func ("/AppStream/store{speed-appdata}", as_test_store_speed_appdata_func); g_test_add_func ("/AppStream/store{speed-desktop}", as_test_store_speed_desktop_func); diff --git a/po/POTFILES.skip b/po/POTFILES.skip index 85fcc78..5c0f3bb 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -1 +1,2 @@ data/tests/intltool.appdata.xml.in +data/tests/usr/share/appdata/broken.appdata.xml |