[gnome-software] Map PackageKit error codes to the GsPlugin domain
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Map PackageKit error codes to the GsPlugin domain
- Date: Mon, 18 Apr 2016 07:58:18 +0000 (UTC)
commit 2e83c74a0d0e1bfe3391ab41913fe00f97c759e2
Author: Richard Hughes <richard hughsie com>
Date: Sun Apr 17 16:47:59 2016 +0100
Map PackageKit error codes to the GsPlugin domain
This allows us to handle them more correctly in the UI.
src/plugins/gs-plugin-packagekit-origin.c | 6 ++-
src/plugins/gs-plugin-packagekit-refine.c | 26 +++++++---
src/plugins/gs-plugin-packagekit-refresh.c | 18 +++++--
src/plugins/gs-plugin-packagekit.c | 36 +++++++++++---
src/plugins/packagekit-common.c | 72 ++++++++++++++++++++++++++++
src/plugins/packagekit-common.h | 1 +
6 files changed, 138 insertions(+), 21 deletions(-)
---
diff --git a/src/plugins/gs-plugin-packagekit-origin.c b/src/plugins/gs-plugin-packagekit-origin.c
index df86d49..1b5cfa5 100644
--- a/src/plugins/gs-plugin-packagekit-origin.c
+++ b/src/plugins/gs-plugin-packagekit-origin.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2013-2014 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2013-2016 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -114,8 +114,10 @@ gs_plugin_packagekit_origin_ensure_sources (GsPlugin *plugin,
cancellable,
NULL, plugin,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
array = pk_results_get_repo_detail_array (results);
for (i = 0; i < array->len; i++) {
rd = g_ptr_array_index (array, i);
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index c69420d..3e5143b 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2013-2014 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2013-2016 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -324,8 +324,10 @@ gs_plugin_packagekit_resolve_packages (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
/* check error code */
error_code = pk_results_get_error_code (results);
@@ -374,8 +376,10 @@ gs_plugin_packagekit_refine_from_desktop (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
/* check error code */
error_code = pk_results_get_error_code (results);
@@ -467,8 +471,10 @@ gs_plugin_packagekit_refine_updatedetails (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
/* set the update details for the update */
array = pk_results_get_update_detail_array (results);
@@ -605,8 +611,10 @@ gs_plugin_packagekit_refine_details (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
/* set the update details for the update */
array = pk_results_get_details_array (results);
@@ -645,8 +653,10 @@ gs_plugin_packagekit_refine_update_urgency (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
/* set the update severity for the app */
sack = pk_results_get_package_sack (results);
@@ -840,8 +850,10 @@ gs_plugin_packagekit_refine_distro_upgrade (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
if (!gs_plugin_packagekit_add_results (plugin, &list, results, error))
return FALSE;
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index 0348f3c..fec0072 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2014 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2014-2016 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -155,8 +155,10 @@ gs_plugin_refresh (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
}
/* download all the packages themselves */
@@ -178,8 +180,10 @@ gs_plugin_refresh (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results2 == NULL)
+ if (results2 == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
}
return TRUE;
@@ -247,8 +251,10 @@ gs_plugin_packagekit_refresh_guess_app_id (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
array = pk_results_get_files_array (results);
if (array->len == 0) {
g_set_error (error,
@@ -326,8 +332,10 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
/* get results */
array = pk_results_get_details_array (results);
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index cc83028..c0b63ac 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2013-2016 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -152,8 +152,10 @@ gs_plugin_add_installed (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
/* add results */
return gs_plugin_packagekit_add_results (plugin, list, results, error);
@@ -195,6 +197,7 @@ gs_plugin_add_sources_related (GsPlugin *plugin,
gs_plugin_packagekit_progress_cb, &data,
error);
if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
ret = FALSE;
goto out;
}
@@ -255,8 +258,10 @@ gs_plugin_add_sources (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
array = pk_results_get_repo_detail_array (results);
for (i = 0; i < array->len; i++) {
@@ -308,7 +313,11 @@ gs_plugin_app_source_enable (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- return results != NULL;
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
+ return FALSE;
+ }
+ return TRUE;
}
/**
@@ -364,6 +373,7 @@ gs_plugin_app_install (GsPlugin *plugin,
gs_plugin_packagekit_progress_cb, &data,
error);
if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
gs_app_set_state_recover (app);
return FALSE;
}
@@ -433,6 +443,7 @@ gs_plugin_app_install (GsPlugin *plugin,
gs_plugin_packagekit_progress_cb, &data,
error);
if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
gs_app_set_state_recover (app);
return FALSE;
}
@@ -458,6 +469,7 @@ gs_plugin_app_install (GsPlugin *plugin,
gs_plugin_packagekit_progress_cb, &data,
error);
if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
gs_app_set_state_recover (app);
return FALSE;
}
@@ -520,7 +532,11 @@ gs_plugin_app_source_disable (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- return results != NULL;
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
+ return FALSE;
+ }
+ return TRUE;
}
/**
@@ -624,6 +640,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
gs_plugin_packagekit_progress_cb, &data,
error);
if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
gs_app_set_state_recover (app);
return FALSE;
}
@@ -684,6 +701,7 @@ gs_plugin_app_upgrade_download (GsPlugin *plugin,
gs_plugin_packagekit_progress_cb, &data,
error);
if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
gs_app_set_state_recover (app);
return FALSE;
}
@@ -722,8 +740,10 @@ gs_plugin_add_search_files (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
/* add results */
return gs_plugin_packagekit_add_results (plugin, list, results, error);
@@ -758,8 +778,10 @@ gs_plugin_add_search_what_provides (GsPlugin *plugin,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
error);
- if (results == NULL)
+ if (results == NULL) {
+ gs_plugin_packagekit_convert_gerror (error);
return FALSE;
+ }
/* add results */
return gs_plugin_packagekit_add_results (plugin, list, results, error);
diff --git a/src/plugins/packagekit-common.c b/src/plugins/packagekit-common.c
index 0c4be79..c4722a4 100644
--- a/src/plugins/packagekit-common.c
+++ b/src/plugins/packagekit-common.c
@@ -85,6 +85,78 @@ packagekit_status_enum_to_plugin_status (PkStatusEnum status)
}
/**
+ * gs_plugin_packagekit_convert_gerror:
+ */
+gboolean
+gs_plugin_packagekit_convert_gerror (GError **error)
+{
+ GError *error_tmp;
+
+ if (error == NULL)
+ return FALSE;
+ error_tmp = *error;
+ if (error_tmp == NULL)
+ return FALSE;
+
+ /* get a local version */
+ if (error_tmp->domain != PK_CLIENT_ERROR)
+ return FALSE;
+
+ /* daemon errors */
+ if (error_tmp->code <= 0xff) {
+ switch (error_tmp->code) {
+ case PK_CLIENT_ERROR_CANNOT_START_DAEMON:
+ case PK_CLIENT_ERROR_INVALID_FILE:
+ case PK_CLIENT_ERROR_NOT_SUPPORTED:
+ error_tmp->code = GS_PLUGIN_ERROR_NOT_SUPPORTED;
+ break;
+ default:
+ error_tmp->code = GS_PLUGIN_ERROR_FAILED;
+ break;
+ }
+
+ /* backend errors */
+ } else {
+ switch (error_tmp->code - 0xff) {
+ case PK_ERROR_ENUM_INVALID_PACKAGE_FILE:
+ case PK_ERROR_ENUM_NOT_SUPPORTED:
+ case PK_ERROR_ENUM_PACKAGE_INSTALL_BLOCKED:
+ error_tmp->code = GS_PLUGIN_ERROR_NOT_SUPPORTED;
+ break;
+ case PK_ERROR_ENUM_CANNOT_FETCH_SOURCES:
+ case PK_ERROR_ENUM_NO_CACHE:
+ case PK_ERROR_ENUM_NO_MORE_MIRRORS_TO_TRY:
+ case PK_ERROR_ENUM_NO_NETWORK:
+ case PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED:
+ error_tmp->code = GS_PLUGIN_ERROR_NO_NETWORK;
+ break;
+ case PK_ERROR_ENUM_BAD_GPG_SIGNATURE:
+ case PK_ERROR_ENUM_CANNOT_INSTALL_REPO_UNSIGNED:
+ case PK_ERROR_ENUM_CANNOT_UPDATE_REPO_UNSIGNED:
+ case PK_ERROR_ENUM_GPG_FAILURE:
+ case PK_ERROR_ENUM_MISSING_GPG_SIGNATURE:
+ case PK_ERROR_ENUM_NO_LICENSE_AGREEMENT:
+ case PK_ERROR_ENUM_NOT_AUTHORIZED:
+ case PK_ERROR_ENUM_RESTRICTED_DOWNLOAD:
+ error_tmp->code = GS_PLUGIN_ERROR_NO_SECURITY;
+ break;
+ case PK_ERROR_ENUM_NO_SPACE_ON_DEVICE:
+ error_tmp->code = GS_PLUGIN_ERROR_NO_SPACE;
+ break;
+ case PK_ERROR_ENUM_CANCELLED_PRIORITY:
+ case PK_ERROR_ENUM_TRANSACTION_CANCELLED:
+ error_tmp->code = GS_PLUGIN_ERROR_CANCELLED;
+ break;
+ default:
+ error_tmp->code = GS_PLUGIN_ERROR_FAILED;
+ break;
+ }
+ }
+ error_tmp->domain = GS_PLUGIN_ERROR;
+ return TRUE;
+}
+
+/**
* gs_plugin_packagekit_add_results:
*/
gboolean
diff --git a/src/plugins/packagekit-common.h b/src/plugins/packagekit-common.h
index c99390b..fda96ab 100644
--- a/src/plugins/packagekit-common.h
+++ b/src/plugins/packagekit-common.h
@@ -36,6 +36,7 @@ gboolean gs_plugin_packagekit_add_results (GsPlugin *plugin,
GList **list,
PkResults *results,
GError **error);
+gboolean gs_plugin_packagekit_convert_gerror (GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]