summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-01-27 19:06:51 +0000
committerRichard Hughes <richard@hughsie.com>2016-01-27 19:06:51 +0000
commit3a849a787659e51f1d0ae5caccef3517d44518c3 (patch)
tree22d1ac5d9c8657d410eb95651ef587f505994471
parentb6cd0775bae56e9c090920cd907a4f76a0802216 (diff)
downloadappstream-glib-3a849a787659e51f1d0ae5caccef3517d44518c3.tar.gz
Add a flag for skipping invalid AppStream files
Fixes https://github.com/hughsie/appstream-glib/issues/83
-rw-r--r--client/as-util.c3
-rw-r--r--libappstream-glib/as-store.c16
-rw-r--r--libappstream-glib/as-store.h2
3 files changed, 18 insertions, 3 deletions
diff --git a/client/as-util.c b/client/as-util.c
index 9f93718..55b7260 100644
--- a/client/as-util.c
+++ b/client/as-util.c
@@ -1246,6 +1246,7 @@ as_util_dump (AsUtilPrivate *priv, gchar **values, GError **error)
store = as_store_new ();
if (g_strcmp0 (values[0], "installed") == 0) {
if (!as_store_load (store,
+ AS_STORE_LOAD_FLAG_IGNORE_INVALID |
AS_STORE_LOAD_FLAG_APPDATA |
AS_STORE_LOAD_FLAG_DESKTOP,
NULL, error)) {
@@ -1253,6 +1254,7 @@ as_util_dump (AsUtilPrivate *priv, gchar **values, GError **error)
}
} else if (g_strcmp0 (values[0], "xdg-app") == 0) {
if (!as_store_load (store,
+ AS_STORE_LOAD_FLAG_IGNORE_INVALID |
AS_STORE_LOAD_FLAG_XDG_APP_USER,
NULL, error)) {
return FALSE;
@@ -1297,6 +1299,7 @@ as_util_search (AsUtilPrivate *priv, gchar **values, GError **error)
/* load system database */
store = as_store_new ();
if (!as_store_load (store,
+ AS_STORE_LOAD_FLAG_IGNORE_INVALID |
AS_STORE_LOAD_FLAG_APP_INFO_SYSTEM |
AS_STORE_LOAD_FLAG_APPDATA |
AS_STORE_LOAD_FLAG_XDG_APP_USER |
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index 97c6b14..d7c28ed 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -1807,6 +1807,7 @@ as_store_load_app_info_file (AsStore *store,
static gboolean
as_store_load_app_info (AsStore *store,
const gchar *path,
+ AsStoreLoadFlags flags,
GCancellable *cancellable,
GError **error)
{
@@ -1832,6 +1833,7 @@ as_store_load_app_info (AsStore *store,
return FALSE;
}
while ((tmp = g_dir_read_name (dir)) != NULL) {
+ GError *error_store = NULL;
g_autofree gchar *filename_md = NULL;
if (g_strcmp0 (tmp, "icons") == 0)
continue;
@@ -1840,8 +1842,16 @@ as_store_load_app_info (AsStore *store,
filename_md,
path,
cancellable,
- error))
- return FALSE;
+ &error_store)) {
+ if (flags & AS_STORE_LOAD_FLAG_IGNORE_INVALID) {
+ g_warning ("Ignoring invalid AppStream file %s: %s",
+ filename_md, error_store->message);
+ g_clear_error (&error_store);
+ } else {
+ g_propagate_error (error, error_store);
+ return FALSE;
+ }
+ }
}
/* watch the directories for changes */
@@ -2291,7 +2301,7 @@ as_store_load (AsStore *store,
dest = g_build_filename (priv->destdir ? priv->destdir : "/", tmp, NULL);
if (!g_file_test (dest, G_FILE_TEST_EXISTS))
continue;
- if (!as_store_load_app_info (store, dest, cancellable, error))
+ if (!as_store_load_app_info (store, dest, flags, cancellable, error))
return FALSE;
}
diff --git a/libappstream-glib/as-store.h b/libappstream-glib/as-store.h
index e8e61f8..ccfe9d8 100644
--- a/libappstream-glib/as-store.h
+++ b/libappstream-glib/as-store.h
@@ -62,6 +62,7 @@ struct _AsStoreClass
* @AS_STORE_LOAD_FLAG_ALLOW_VETO: Add vetoed applications
* @AS_STORE_LOAD_FLAG_XDG_APP_USER: Add xdg-app user applications
* @AS_STORE_LOAD_FLAG_XDG_APP_SYSTEM: Add xdg-app system applications
+ * @AS_STORE_LOAD_FLAG_IGNORE_INVALID: Ignore invalid files
*
* The flags to use when loading the store.
**/
@@ -75,6 +76,7 @@ typedef enum {
AS_STORE_LOAD_FLAG_ALLOW_VETO = 32, /* Since: 0.2.5 */
AS_STORE_LOAD_FLAG_XDG_APP_USER = 64, /* Since: 0.5.7 */
AS_STORE_LOAD_FLAG_XDG_APP_SYSTEM = 128, /* Since: 0.5.7 */
+ AS_STORE_LOAD_FLAG_IGNORE_INVALID = 256, /* Since: 0.5.8 */
/*< private >*/
AS_STORE_LOAD_FLAG_LAST
} AsStoreLoadFlags;