summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2018-10-30 17:06:29 +0000
committerRichard Hughes <richard@hughsie.com>2018-11-01 10:49:36 +0000
commit89d3d99c10e58f7a312ff15f2ade20d584f21d7e (patch)
treebab708fdaf9f480ceb7b6bf4cd58a0b745a9cae3
parentcaf8cd85b79a5bc4f1f4673846657ce39906579e (diff)
downloadappstream-glib-89d3d99c10e58f7a312ff15f2ade20d584f21d7e.tar.gz
as-store: Guarantee to return G_IO_ERROR_NOT_FOUND when loading fails
Previously, as_store_from_file() would either return G_IO_ERROR_NOT_FOUND or AS_STORE_ERROR_FAILED if the given file did not exist, depending on its file extension. That is not particularly helpful for callers. Instead, guarantee to always return G_IO_ERROR_NOT_FOUND if the file was not found. Signed-off-by: Philip Withnall <withnall@endlessm.com>
-rw-r--r--libappstream-glib/as-store.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index 66558b6..d2075eb 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -2017,7 +2017,10 @@ as_store_from_file_internal (AsStore *store,
if (priv->add_flags & AS_STORE_ADD_FLAG_ONLY_NATIVE_LANGS)
flags |= AS_NODE_FROM_XML_FLAG_ONLY_NATIVE_LANGS;
root = as_node_from_file (file, flags, cancellable, &error_local);
- if (root == NULL) {
+ if (root == NULL && g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
+ g_propagate_error (error, g_steal_pointer (&error_local));
+ return FALSE;
+ } else if (root == NULL) {
g_set_error (error,
AS_STORE_ERROR,
AS_STORE_ERROR_FAILED,
@@ -2058,6 +2061,9 @@ as_store_from_file_internal (AsStore *store,
* as_store_set_origin() should be called *before* this function if cached
* icons are required.
*
+ * If @file does not exist, %G_IO_ERROR_NOT_FOUND will be returned. Other
+ * #GIOErrors and #AsStoreErrors may be returned as appropriate.
+ *
* Returns: %TRUE for success
*
* Since: 0.1.0