static void pk_direct_error_cb (PkBackendJob *job, gpointer object, gpointer user_data) { PkError *err = PK_ERROR_CODE (object); g_print ("Error: %s\t%s\n", pk_error_enum_to_string (pk_error_get_code (err)), pk_error_get_details (err)); }
/** * gpk_log_get_old_transactions_cb **/ static void gpk_log_get_old_transactions_cb (GObject *object, GAsyncResult *res, gpointer user_data) { // PkClient *client = PK_CLIENT (object); GError *error = NULL; PkResults *results = NULL; PkError *error_code = NULL; /* get the results */ results = pk_client_generic_finish (client, res, &error); if (results == NULL) { egg_warning ("failed to get old transactions: %s", error->message); g_error_free (error); goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { egg_warning ("failed to get old transactions: %s, %s", pk_error_enum_to_text (pk_error_get_code (error_code)), pk_error_get_details (error_code)); goto out; } /* get the list */ if (transactions != NULL) g_ptr_array_unref (transactions); transactions = pk_results_get_transaction_array (results); gpk_log_refilter (); out: if (error_code != NULL) g_object_unref (error_code); if (results != NULL) g_object_unref (results); }
/** * pk_debuginfo_install_get_repo_list: **/ static gboolean pk_debuginfo_install_get_repo_list (PkDebuginfoInstallPrivate *priv, GError **error) { gboolean ret = FALSE; PkResults *results = NULL; guint i; GPtrArray *array; GError *error_local = NULL; PkRepoDetail *item; PkError *error_code = NULL; gboolean enabled; gchar *repo_id; /* get all repo details */ results = pk_client_get_repo_list (priv->client, pk_bitfield_value (PK_FILTER_ENUM_NONE), NULL, NULL, NULL, &error_local); if (results == NULL) { *error = g_error_new (1, 0, "failed to get repo list: %s", error_local->message); g_error_free (error_local); goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { *error = g_error_new (1, 0, "failed to get repo list: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); goto out; } /* get results */ array = pk_results_get_repo_detail_array (results); for (i=0; i<array->len; i++) { item = g_ptr_array_index (array, i); g_object_get (item, "enabled", &enabled, "repo-id", &repo_id, NULL); if (enabled) g_ptr_array_add (priv->enabled, repo_id); else g_ptr_array_add (priv->disabled, repo_id); } ret = TRUE; out: if (error_code != NULL) g_object_unref (error_code); if (results != NULL) g_object_unref (results); return ret; }
/** * pk_debuginfo_install_add_deps: **/ static gboolean pk_debuginfo_install_add_deps (PkDebuginfoInstallPrivate *priv, GPtrArray *packages_search, GPtrArray *packages_results, GError **error) { gboolean ret = TRUE; PkResults *results = NULL; PkPackage *item; gchar *package_id = NULL; GPtrArray *list = NULL; GError *error_local = NULL; gchar **package_ids = NULL; gchar *name_debuginfo; guint i; gchar **split; PkError *error_code = NULL; /* get depends for them all, not adding dup's */ package_ids = pk_ptr_array_to_strv (packages_search); results = pk_client_get_depends (priv->client, pk_bitfield_value (PK_FILTER_ENUM_NONE), package_ids, TRUE, NULL, NULL, NULL, &error_local); if (results == NULL) { *error = g_error_new (1, 0, "failed to get_depends: %s", error_local->message); g_error_free (error_local); ret = FALSE; goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { *error = g_error_new (1, 0, "failed to get depends: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); ret = FALSE; goto out; } /* add dependent packages */ list = pk_results_get_package_array (results); for (i=0; i<list->len; i++) { item = g_ptr_array_index (list, i); split = pk_package_id_split (pk_package_get_id (item)); /* add -debuginfo */ name_debuginfo = pk_debuginfo_install_name_to_debuginfo (split[PK_PACKAGE_ID_NAME]); g_strfreev (split); /* resolve name */ g_debug ("resolving: %s", name_debuginfo); package_id = pk_debuginfo_install_resolve_name_to_id (priv, name_debuginfo, &error_local); if (package_id == NULL) { /* TRANSLATORS: we couldn't find the package name, non-fatal */ g_print (_("Failed to find the package %s, or already installed: %s"), name_debuginfo, error_local->message); g_print ("\n"); g_error_free (error_local); /* don't quit, this is non-fatal */ error = NULL; } /* add to array to install */ if (package_id != NULL && !g_str_has_suffix (package_id, "installed")) { g_debug ("going to try to install (for deps): %s", package_id); g_ptr_array_add (packages_results, g_strdup (package_id)); } g_free (package_id); g_free (name_debuginfo); } out: if (error_code != NULL) g_object_unref (error_code); if (results != NULL) g_object_unref (results); if (list != NULL) g_ptr_array_unref (list); g_strfreev (package_ids); return ret; }
/** * pk_debuginfo_install_resolve_name_to_id: **/ static gchar * pk_debuginfo_install_resolve_name_to_id (PkDebuginfoInstallPrivate *priv, const gchar *package_name, GError **error) { PkResults *results = NULL; PkPackage *item; gchar *package_id = NULL; GPtrArray *list = NULL; GError *error_local = NULL; gchar **names; PkError *error_code = NULL; /* resolve takes a char** */ names = g_strsplit (package_name, ";", -1); /* resolve */ results = pk_client_resolve (priv->client, pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST, -1), names, NULL, NULL, NULL, &error_local); if (results == NULL) { *error = g_error_new (1, 0, "failed to resolve: %s", error_local->message); g_error_free (error_local); goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { *error = g_error_new (1, 0, "failed to resolve: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); goto out; } /* check we only got one match */ list = pk_results_get_package_array (results); if (list->len == 0) { *error = g_error_new (1, 0, "no package %s found", package_name); goto out; } if (list->len > 1) { *error = g_error_new (1, 0, "more than one package found for %s", package_name); goto out; } /* get the package id */ item = g_ptr_array_index (list, 0); package_id = g_strdup (pk_package_get_id (item)); out: if (error_code != NULL) g_object_unref (error_code); if (results != NULL) g_object_unref (results); if (list != NULL) g_ptr_array_unref (list); g_strfreev (names); return package_id; }
/** * pk_debuginfo_install_packages_install: **/ static gboolean pk_debuginfo_install_packages_install (PkDebuginfoInstallPrivate *priv, GPtrArray *array, GError **error) { gboolean ret = TRUE; PkResults *results = NULL; gchar **package_ids; GError *error_local = NULL; PkError *error_code = NULL; /* mush back into a char** */ package_ids = pk_ptr_array_to_strv (array); /* TRANSLATORS: we are starting to install the packages */ pk_progress_bar_start (priv->progress_bar, _("Starting install")); /* enable this repo */ results = pk_task_install_packages_sync (PK_TASK(priv->client), package_ids, NULL, (PkProgressCallback) pk_debuginfo_install_progress_cb, priv, &error_local); if (results == NULL) { *error = g_error_new (1, 0, "failed to install packages: %s", error_local->message); g_error_free (error_local); ret = FALSE; goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { *error = g_error_new (1, 0, "failed to resolve: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); ret = FALSE; goto out; } /* end progressbar output */ pk_progress_bar_end (priv->progress_bar); out: if (error_code != NULL) g_object_unref (error_code); if (results != NULL) g_object_unref (results); g_strfreev (package_ids); return ret; }
/** * pk_debuginfo_install_enable_repos: **/ static gboolean pk_debuginfo_install_enable_repos (PkDebuginfoInstallPrivate *priv, GPtrArray *array, gboolean enable, GError **error) { guint i; gboolean ret = TRUE; PkResults *results = NULL; const gchar *repo_id; GError *error_local = NULL; PkError *error_code = NULL; /* enable all debuginfo repos we found */ for (i=0; i<array->len; i++) { repo_id = g_ptr_array_index (array, i); /* enable this repo */ results = pk_client_repo_enable (priv->client, repo_id, enable, NULL, NULL, NULL, &error_local); if (results == NULL) { *error = g_error_new (1, 0, "failed to enable %s: %s", repo_id, error_local->message); g_error_free (error_local); ret = FALSE; goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { *error = g_error_new (1, 0, "failed to enable repo: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); ret = FALSE; goto out; } g_debug ("setting %s: %i", repo_id, enable); g_object_unref (results); } out: if (error_code != NULL) g_object_unref (error_code); return ret; }
/** * pk_offline_auth_set_results: * @results: A #PkResults * @error: A #GError or %NULL * * Saves the transaction results to a file. * * Return value: %TRUE for success, else %FALSE and @error set * * Since: 0.9.6 **/ gboolean pk_offline_auth_set_results (PkResults *results, GError **error) { guint i; PkPackage *package; g_autoptr(GError) error_local = NULL; g_autofree gchar *data = NULL; g_autoptr(GKeyFile) key_file = NULL; g_autoptr(PkError) pk_error = NULL; g_autoptr(GPtrArray) packages = NULL; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); key_file = g_key_file_new (); pk_error = pk_results_get_error_code (results); if (pk_error != NULL) { g_key_file_set_boolean (key_file, PK_OFFLINE_RESULTS_GROUP, "Success", FALSE); g_key_file_set_string (key_file, PK_OFFLINE_RESULTS_GROUP, "ErrorCode", pk_error_enum_to_string (pk_error_get_code (pk_error))); g_key_file_set_string (key_file, PK_OFFLINE_RESULTS_GROUP, "ErrorDetails", pk_error_get_details (pk_error)); } else { g_key_file_set_boolean (key_file, PK_OFFLINE_RESULTS_GROUP, "Success", TRUE); } /* save packages if any set */ packages = pk_results_get_package_array (results); if (packages->len > 0) { g_autoptr(GString) string = NULL; string = g_string_new (""); for (i = 0; i < packages->len; i++) { package = g_ptr_array_index (packages, i); switch (pk_package_get_info (package)) { case PK_INFO_ENUM_UPDATING: case PK_INFO_ENUM_INSTALLING: g_string_append_printf (string, "%s,", pk_package_get_id (package)); break; default: break; } } if (string->len > 0) g_string_set_size (string, string->len - 1); g_key_file_set_string (key_file, PK_OFFLINE_RESULTS_GROUP, "Packages", string->str); } /* write file */ data = g_key_file_to_data (key_file, NULL, &error_local); if (data == NULL) { g_set_error (error, PK_OFFLINE_ERROR, PK_OFFLINE_ERROR_FAILED, "failed to get keyfile data: %s", error_local->message); return FALSE; } if (!g_file_set_contents (PK_OFFLINE_RESULTS_FILENAME, data, -1, &error_local)) { g_set_error (error, PK_OFFLINE_ERROR, PK_OFFLINE_ERROR_FAILED, "failed to write file: %s", error_local->message); return FALSE; } return TRUE; }
/** * pk_cnf_install_package_id: **/ static gboolean pk_cnf_install_package_id (const gchar *package_id) { _cleanup_error_free_ GError *error = NULL; _cleanup_object_unref_ PkError *error_code = NULL; _cleanup_object_unref_ PkResults *results = NULL; _cleanup_strv_free_ gchar **package_ids = NULL; /* do install */ package_ids = pk_package_ids_from_id (package_id); results = pk_task_install_packages_sync (task, package_ids, cancellable, (PkProgressCallback) pk_cnf_progress_cb, NULL, &error); if (results == NULL) { /* TRANSLATORS: we failed to install the package */ g_printerr ("%s: %s\n", _("Failed to install packages"), error->message); return FALSE; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { /* TRANSLATORS: the transaction failed in a way we could not expect */ g_printerr ("%s: %s, %s\n", _("The transaction failed"), pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); return FALSE; } return TRUE; }
/** * pk_console_resolve_package: **/ gchar * pk_console_resolve_package (PkClient *client, PkBitfield filter, const gchar *package_name, GError **error) { const gchar *package_id_tmp; gchar *package_id = NULL; gboolean valid; gchar **tmp; gchar **split = NULL; PkResults *results; GPtrArray *array = NULL; guint i; gchar *printable; PkPackage *package; PkError *error_code = NULL; /* have we passed a complete package_id? */ valid = pk_package_id_check (package_name); if (valid) return g_strdup (package_name); /* split */ tmp = g_strsplit (package_name, ",", -1); /* get the list of possibles */ results = pk_client_resolve (client, filter, tmp, NULL, NULL, NULL, error); if (results == NULL) goto out; /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { g_set_error (error, 1, 0, "\n%s", pk_error_get_details (error_code)); goto out; } /* get the packages returned */ array = pk_results_get_package_array (results); if (array == NULL) { g_set_error (error, 1, 0, "did not get package struct for %s", package_name); goto out; } /* nothing found */ if (array->len == 0) { g_set_error (error, 1, 0, "could not find %s", package_name); goto out; } /* just one thing found */ if (array->len == 1) { package = g_ptr_array_index (array, 0); g_object_get (package, "package-id", &package_id, NULL); goto out; } /* TRANSLATORS: more than one package could be found that matched, to follow is a list of possible packages */ g_print ("%s\n", _("More than one package matches:")); for (i=0; i<array->len; i++) { package = g_ptr_array_index (array, i); package_id_tmp = pk_package_get_id (package); split = pk_package_id_split (package_id_tmp); printable = pk_package_id_to_printable (package_id_tmp); g_print ("%i. %s [%s]\n", i+1, printable, split[PK_PACKAGE_ID_DATA]); g_free (printable); } /* TRANSLATORS: This finds out which package in the list to use */ i = pk_console_get_number (_("Please choose the correct package: "), array->len); if (i == 0) { g_set_error_literal (error, 1, 0, "User aborted selection"); goto out; } package = g_ptr_array_index (array, i-1); g_object_get (package, "package-id", &package_id, NULL); out: if (results != NULL) g_object_unref (results); if (array != NULL) g_ptr_array_unref (array); g_strfreev (tmp); g_strfreev (split); return package_id; }
/** * pk_offline_update_write_results: **/ static void pk_offline_update_write_results (PkResults *results) { gboolean ret; gchar *data = NULL; GError *error = NULL; GKeyFile *key_file; GPtrArray *packages; GString *string; guint i; PkError *pk_error; PkPackage *package; key_file = g_key_file_new (); pk_error = pk_results_get_error_code (results); if (pk_error != NULL) { g_key_file_set_boolean (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Success", FALSE); g_key_file_set_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "ErrorCode", pk_error_enum_to_string (pk_error_get_code (pk_error))); g_key_file_set_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "ErrorDetails", pk_error_get_details (pk_error)); } else { g_key_file_set_boolean (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Success", TRUE); } /* save packages if any set */ packages = pk_results_get_package_array (results); if (packages != NULL) { string = g_string_new (""); for (i = 0; i < packages->len; i++) { package = g_ptr_array_index (packages, i); switch (pk_package_get_info (package)) { case PK_INFO_ENUM_UPDATING: case PK_INFO_ENUM_INSTALLING: g_string_append_printf (string, "%s,", pk_package_get_id (package)); break; default: break; } } if (string->len > 0) g_string_set_size (string, string->len - 1); g_key_file_set_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Packages", string->str); g_string_free (string, TRUE); } /* write file */ data = g_key_file_to_data (key_file, NULL, &error); if (data == NULL) { g_warning ("failed to get keyfile data: %s", error->message); g_error_free (error); goto out; } ret = g_file_set_contents (PK_OFFLINE_UPDATE_RESULTS_FILENAME, data, -1, &error); if (!ret) { g_warning ("failed to write file: %s", error->message); g_error_free (error); goto out; } out: g_key_file_free (key_file); g_free (data); }
void gs_offline_updates_show_error (void) { const gchar *title; gboolean show_geeky = FALSE; GtkWidget *dialog; _cleanup_error_free_ GError *error = NULL; _cleanup_object_unref_ PkError *pk_error = NULL; _cleanup_object_unref_ PkResults *results = NULL; _cleanup_string_free_ GString *msg = NULL; results = pk_offline_get_results (NULL); if (results == NULL) return; pk_error = pk_results_get_error_code (results); if (pk_error == NULL) return; /* can this happen in reality? */ if (pk_results_get_exit_code (results) == PK_EXIT_ENUM_SUCCESS) return; /* TRANSLATORS: this is when the offline update failed */ title = _("Failed To Update"); msg = g_string_new (""); switch (pk_error_get_code (pk_error)) { case PK_ERROR_ENUM_UNFINISHED_TRANSACTION: /* TRANSLATORS: the transaction could not be completed * as a previous transaction was unfinished */ g_string_append (msg, _("A previous update was unfinished.")); show_geeky = TRUE; break; case PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED: case PK_ERROR_ENUM_NO_CACHE: case PK_ERROR_ENUM_NO_NETWORK: case PK_ERROR_ENUM_NO_MORE_MIRRORS_TO_TRY: case PK_ERROR_ENUM_CANNOT_FETCH_SOURCES: /* TRANSLATORS: the package manager needed to download * something with no network available */ g_string_append (msg, _("Network access was required but not available.")); break; case PK_ERROR_ENUM_BAD_GPG_SIGNATURE: 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_PACKAGE_CORRUPT: /* TRANSLATORS: if the package is not signed correctly * */ g_string_append (msg, _("An update was not signed in the correct way.")); show_geeky = TRUE; break; case PK_ERROR_ENUM_DEP_RESOLUTION_FAILED: case PK_ERROR_ENUM_FILE_CONFLICTS: case PK_ERROR_ENUM_INCOMPATIBLE_ARCHITECTURE: case PK_ERROR_ENUM_PACKAGE_CONFLICTS: /* TRANSLATORS: the transaction failed in a way the user * probably cannot comprehend. Package management systems * really are teh suck.*/ g_string_append (msg, _("The update could not be completed.")); show_geeky = TRUE; break; case PK_ERROR_ENUM_TRANSACTION_CANCELLED: /* TRANSLATORS: the user aborted the update manually */ g_string_append (msg, _("The update was cancelled.")); break; case PK_ERROR_ENUM_NO_PACKAGES_TO_UPDATE: case PK_ERROR_ENUM_UPDATE_NOT_FOUND: /* TRANSLATORS: the user must have updated manually after * the updates were prepared */ g_string_append (msg, _("An offline update was requested but no packages required updating.")); break; case PK_ERROR_ENUM_NO_SPACE_ON_DEVICE: /* TRANSLATORS: we ran out of disk space */ g_string_append (msg, _("No space was left on the drive.")); break; case PK_ERROR_ENUM_PACKAGE_FAILED_TO_BUILD: case PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL: case PK_ERROR_ENUM_PACKAGE_FAILED_TO_REMOVE: /* TRANSLATORS: the update process failed in a general * way, usually this message will come from source distros * like gentoo */ g_string_append (msg, _("An update failed to install correctly.")); show_geeky = TRUE; break; default: /* TRANSLATORS: We didn't handle the error type */ g_string_append (msg, _("The offline update failed in an unexpected way.")); show_geeky = TRUE; break; } if (show_geeky) { g_string_append_printf (msg, "\n%s\n\n%s", /* TRANSLATORS: these are geeky messages from the * package manager no mortal is supposed to understand, * but google might know what they mean */ _("Detailed errors from the package manager follow:"), pk_error_get_details (pk_error)); } dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "%s", title); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", msg->str); g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); gtk_widget_show (dialog); if (!pk_offline_clear_results (NULL, &error)) { g_warning ("Failure clearing offline update message: %s", error->message); } }