diff options
author | Richard Hughes <richard@hughsie.com> | 2017-06-01 09:59:15 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2017-06-01 09:59:46 +0100 |
commit | 8f5869f2bc5b9256bdd09fe753aa1f12cbc0374d (patch) | |
tree | 90bfc46b611de69ee73787649616822483c83194 /libappstream-builder/asb-task.c | |
parent | 85b19c63089ea1d719e352b6b1e78b5b090d80f3 (diff) | |
download | appstream-glib-8f5869f2bc5b9256bdd09fe753aa1f12cbc0374d.tar.gz |
Actually return failure if the AsbTask fails
Now that we're not threaded we can provide a sane error.
Diffstat (limited to 'libappstream-builder/asb-task.c')
-rw-r--r-- | libappstream-builder/asb-task.c | 96 |
1 files changed, 38 insertions, 58 deletions
diff --git a/libappstream-builder/asb-task.c b/libappstream-builder/asb-task.c index 5bf8971..2210c6a 100644 --- a/libappstream-builder/asb-task.c +++ b/libappstream-builder/asb-task.c @@ -317,12 +317,10 @@ asb_task_process (AsbTask *task, GError **error) AsbPlugin *plugin = NULL; AsbTaskPrivate *priv = GET_PRIVATE (task); GList *apps = NULL; - GList *l; GPtrArray *array; gboolean ret; guint i; guint nr_added = 0; - g_autoptr(GError) error = NULL; g_autofree gchar *basename = NULL; /* reset the profile timer */ @@ -342,13 +340,10 @@ asb_task_process (AsbTask *task, GError **error) GPtrArray *apps_tmp; g_autoptr(AsStore) store = as_store_new (); g_autoptr(GFile) file = g_file_new_for_path (priv->filename); - if (!as_store_from_file (store, file, NULL, NULL, &error)) { - asb_package_log (priv->pkg, - ASB_PACKAGE_LOG_LEVEL_WARNING, - "Failed to parse %s: %s", - asb_package_get_filename (priv->pkg), - error->message); - return TRUE; + if (!as_store_from_file (store, file, NULL, NULL, error)) { + g_prefix_error (error, "Failed to parse %s: ", + asb_package_get_filename (priv->pkg)); + return FALSE; } apps_tmp = as_store_get_apps (store); for (i = 0; i < apps_tmp->len; i++) { @@ -378,16 +373,17 @@ asb_task_process (AsbTask *task, GError **error) asb_task_add_suitable_plugins (task); if (priv->plugins_to_run->len == 0) { asb_context_add_app_ignore (priv->ctx, priv->pkg); - goto out; + asb_package_close (priv->pkg, NULL); + asb_package_clear (priv->pkg, + ASB_PACKAGE_ENSURE_DEPS | + ASB_PACKAGE_ENSURE_FILES); + return TRUE; } /* delete old tree if it exists */ - ret = asb_utils_ensure_exists_and_empty (priv->tmpdir, &error); - if (!ret) { - asb_package_log (priv->pkg, - ASB_PACKAGE_LOG_LEVEL_WARNING, - "Failed to clear: %s", error->message); - goto out; + if (!asb_utils_ensure_exists_and_empty (priv->tmpdir, error)) { + g_prefix_error (error, "Failed to clear: "); + return FALSE; } /* explode tree */ @@ -396,16 +392,12 @@ asb_task_process (AsbTask *task, GError **error) ASB_PACKAGE_LOG_LEVEL_DEBUG, "Exploding tree for %s", asb_package_get_name (priv->pkg)); - ret = asb_package_explode (priv->pkg, - priv->tmpdir, - asb_context_get_file_globs (priv->ctx), - &error); - if (!ret) { - asb_package_log (priv->pkg, - ASB_PACKAGE_LOG_LEVEL_WARNING, - "Failed to explode: %s", error->message); - g_clear_error (&error); - goto skip; + if (!asb_package_explode (priv->pkg, + priv->tmpdir, + asb_context_get_file_globs (priv->ctx), + error)) { + g_prefix_error (error, "Failed to explode: "); + return FALSE; } /* add extra packages */ @@ -414,46 +406,41 @@ asb_task_process (AsbTask *task, GError **error) ASB_PACKAGE_ENSURE_SOURCE, error)) return FALSE; - ret = asb_task_explode_extra_packages (task, &error); - if (!ret) { - asb_package_log (priv->pkg, - ASB_PACKAGE_LOG_LEVEL_WARNING, - "Failed to explode extra file: %s", - error->message); - g_clear_error (&error); - goto skip; + if (!asb_task_explode_extra_packages (task, error)) { + g_prefix_error (error, "Failed to explode extra files: "); + return FALSE; } /* run plugins */ g_debug ("examining: %s", asb_package_get_name (priv->pkg)); for (i = 0; i < priv->plugins_to_run->len; i++) { GList *apps_tmp = NULL; + g_autoptr(GError) error_local = NULL; plugin = g_ptr_array_index (priv->plugins_to_run, i); asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_DEBUG, "Processing %s with %s", basename, plugin->name); - apps_tmp = asb_plugin_process (plugin, priv->pkg, priv->tmpdir, &error); + apps_tmp = asb_plugin_process (plugin, priv->pkg, priv->tmpdir, &error_local); if (apps_tmp == NULL) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to run process '%s': %s", - plugin->name, error->message); - g_clear_error (&error); + plugin->name, error_local->message); + continue; } - for (l = apps_tmp; l != NULL; l = l->next) { + for (GList *l = apps_tmp; l != NULL; l = l->next) { app = ASB_APP (l->data); asb_plugin_add_app (&apps, AS_APP (app)); } g_list_free_full (apps_tmp, g_object_unref); } - if (apps == NULL) - goto skip; /* print */ g_debug ("processing: %s", asb_package_get_name (priv->pkg)); - for (l = apps; l != NULL; l = l->next) { + for (GList *l = apps; l != NULL; l = l->next) { + g_autoptr(GError) error_local = NULL; app = l->data; /* never set */ @@ -506,15 +493,14 @@ asb_task_process (AsbTask *task, GError **error) priv->pkg, app, priv->tmpdir, - &error); + &error_local); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to run process on %s: %s", as_app_get_id (AS_APP (app)), - error->message); - g_clear_error (&error); - goto skip; + error_local->message); + continue; } /* set the VCS information into the metadata */ @@ -539,24 +525,18 @@ asb_task_process (AsbTask *task, GError **error) skip: /* delete tree */ g_debug ("deleting temp files: %s", asb_package_get_name (priv->pkg)); - if (!asb_utils_rmtree (priv->tmpdir, &error)) { - asb_package_log (priv->pkg, - ASB_PACKAGE_LOG_LEVEL_WARNING, - "Failed to delete tree: %s", - error->message); - goto out; + if (!asb_utils_rmtree (priv->tmpdir, error)) { + g_prefix_error (error, "Failed to delete tree: "); + return FALSE; } /* write log */ g_debug ("writing log: %s", asb_package_get_name (priv->pkg)); - if (!asb_package_log_flush (priv->pkg, &error)) { - asb_package_log (priv->pkg, - ASB_PACKAGE_LOG_LEVEL_WARNING, - "Failed to write package log: %s", - error->message); - goto out; + if (!asb_package_log_flush (priv->pkg, error)) { + g_prefix_error (error, "Failed to write package log: "); + return FALSE; } -out: + /* clear loaded resources */ asb_package_close (priv->pkg, NULL); asb_package_clear (priv->pkg, |