Пример #1
0
/**
 * pk_offline_update_write_error:
 **/
static void
pk_offline_update_write_error (const GError *error)
{
	_cleanup_error_free_ GError *error_local = NULL;
	_cleanup_object_unref_ PkError *pk_error = NULL;
	_cleanup_object_unref_ PkResults *results = NULL;

	sd_journal_print (LOG_INFO, "writing failed results");
	results = pk_results_new ();
	pk_results_set_exit_code (results, PK_EXIT_ENUM_FAILED);
	pk_error = pk_error_new ();
	g_object_set (pk_error,
		      "code", PK_ERROR_ENUM_FAILED_INITIALIZATION,
		      "details", error->message,
		      NULL);
	pk_results_set_error_code (results, pk_error);
	if (!pk_offline_auth_set_results (results, &error_local))
		sd_journal_print (LOG_WARNING, "%s", error_local->message);
}
Пример #2
0
/**
 * pk_offline_update_write_dummy_results:
 *
 * If the transaction crashes, the kernel oopses or we loose power
 * during the transaction then we never get a chance to write the actual
 * transaction success / failure file.
 *
 * Write a dummy file so at least the user gets notified that something
 * bad happened.
 **/
static void
pk_offline_update_write_dummy_results (gchar **package_ids)
{
	_cleanup_error_free_ GError *error = NULL;
	_cleanup_object_unref_ PkError *pk_error = NULL;
	_cleanup_object_unref_ PkResults *results = NULL;

	sd_journal_print (LOG_INFO, "writing dummy results");
	results = pk_results_new ();
	pk_results_set_exit_code (results, PK_EXIT_ENUM_FAILED);
	pk_error = pk_error_new ();
	g_object_set (pk_error,
		      "code", PK_ERROR_ENUM_FAILED_INITIALIZATION,
		      "details", "The transaction did not complete",
		      NULL);
	pk_results_set_error_code (results, pk_error);
	if (!pk_offline_auth_set_results (results, &error))
		sd_journal_print (LOG_WARNING, "%s", error->message);

	/* ensure this is written to disk */
	sync ();
}
Пример #3
0
/**
 * pk_offline_get_results:
 * @error: A #GError or %NULL
 *
 * Gets the last result of the offline transaction.
 *
 * Return value: (transfer full): A #PkResults, or %NULL
 *
 * Since: 0.9.6
 **/
PkResults *
pk_offline_get_results (GError **error)
{
	gboolean ret;
	gboolean success;
	guint i;
	g_autoptr(GError) error_local = NULL;
	g_autofree gchar *data = NULL;
	g_autoptr(GKeyFile) file = NULL;
	g_autoptr(PkError) pk_error = NULL;
	g_autoptr(PkResults) results = NULL;
	g_auto(GStrv) package_ids = NULL;

	g_return_val_if_fail (error == NULL || *error == NULL, NULL);

	/* does not exist */
	if (!g_file_test (PK_OFFLINE_RESULTS_FILENAME, G_FILE_TEST_EXISTS)) {
		g_set_error_literal (error,
				     PK_OFFLINE_ERROR,
				     PK_OFFLINE_ERROR_NO_DATA,
				     "no update results available");
		return NULL;
	}

	/* load data */
	file = g_key_file_new ();
	ret = g_key_file_load_from_file (file,
					 PK_OFFLINE_RESULTS_FILENAME,
					 G_KEY_FILE_NONE,
					 &error_local);
	if (!ret) {
		g_set_error (error,
			     PK_OFFLINE_ERROR,
			     PK_OFFLINE_ERROR_FAILED,
			     "results file invalid: %s",
			     error_local->message);
		return NULL;
	}

	/* add error */
	results = pk_results_new ();
	success = g_key_file_get_boolean (file, PK_OFFLINE_RESULTS_GROUP,
					  "Success", NULL);
	if (!success) {
		g_autofree gchar *details = NULL;
		g_autofree gchar *enum_str = NULL;
		pk_error = pk_error_new ();
		enum_str = g_key_file_get_string (file,
						  PK_OFFLINE_RESULTS_GROUP,
						  "ErrorCode",
						  NULL);
		details = g_key_file_get_string (file,
						 PK_OFFLINE_RESULTS_GROUP,
						 "ErrorDetails",
						 NULL);
		g_object_set (pk_error,
			      "code", pk_error_enum_from_string (enum_str),
			      "details", details,
			      NULL);
		pk_results_set_error_code (results, pk_error);
		pk_results_set_exit_code (results, PK_EXIT_ENUM_FAILED);
	} else {
		pk_results_set_exit_code (results, PK_EXIT_ENUM_SUCCESS);
	}

	/* add packages */
	data = g_key_file_get_string (file, PK_OFFLINE_RESULTS_GROUP,
				      "Packages", NULL);
	if (data != NULL) {
		package_ids = g_strsplit (data, ",", -1);
		for (i = 0; package_ids[i] != NULL; i++) {
			g_autoptr(PkPackage) pkg = NULL;
			pkg = pk_package_new ();
			pk_package_set_info (pkg, PK_INFO_ENUM_UPDATING);
			if (!pk_package_set_id (pkg, package_ids[i], error))
				return NULL;
			pk_results_add_package (results, pkg);
		}
	}
	return g_object_ref (results);
}