Example #1
0
/**
 * pk_offline_auth_invalidate:
 * @error: A #GError or %NULL
 *
 * Invalidates the offline operation. This is normally done when the package
 * cache has been refreshed, or a package listed in the prepared transaction
 * is manually installed or removed.
 *
 * Return value: %TRUE for success, else %FALSE and @error set
 *
 * Since: 0.9.6
 **/
gboolean
pk_offline_auth_invalidate (GError **error)
{
	_cleanup_error_free_ GError *error_local = NULL;
	_cleanup_object_unref_ GFile *file = NULL;

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

	/* cancel the pending update */
	if (!pk_offline_auth_cancel (error))
		return FALSE;

	/* delete the prepared file */
	file = g_file_new_for_path (PK_OFFLINE_PREPARED_FILENAME);
	if (g_file_query_exists (file, NULL) &&
	    !g_file_delete (file, NULL, &error_local)) {
		g_set_error (error,
			     PK_OFFLINE_ERROR,
			     PK_OFFLINE_ERROR_FAILED,
			     "Cannot delete %s: %s",
			     PK_OFFLINE_PREPARED_FILENAME,
			     error_local->message);
		return FALSE;
	}
	return TRUE;
}
Example #2
0
/**
 * pk_offline_auth_invalidate:
 * @error: A #GError or %NULL
 *
 * Invalidates the offline operation. This is normally done when the package
 * cache has been refreshed, or a package listed in the prepared transaction
 * is manually installed or removed.
 *
 * Return value: %TRUE for success, else %FALSE and @error set
 *
 * Since: 0.9.6
 **/
gboolean
pk_offline_auth_invalidate (GError **error)
{
	g_autoptr(GError) error_local = NULL;
	g_autoptr(GFile) file1 = NULL;
	g_autoptr(GFile) file2 = NULL;

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

	/* cancel the pending update */
	if (!pk_offline_auth_cancel (error))
		return FALSE;

	/* delete the prepared file */
	file1 = g_file_new_for_path (PK_OFFLINE_PREPARED_FILENAME);
	if (g_file_query_exists (file1, NULL) &&
	    !g_file_delete (file1, NULL, &error_local)) {
		g_set_error (error,
			     PK_OFFLINE_ERROR,
			     PK_OFFLINE_ERROR_FAILED,
			     "Cannot delete %s: %s",
			     PK_OFFLINE_PREPARED_FILENAME,
			     error_local->message);
		return FALSE;
	}

	/* delete the prepared system upgrade file */
	file2 = g_file_new_for_path (PK_OFFLINE_PREPARED_UPGRADE_FILENAME);
	if (g_file_query_exists (file2, NULL) &&
	    !g_file_delete (file2, NULL, &error_local)) {
		g_set_error (error,
			     PK_OFFLINE_ERROR,
			     PK_OFFLINE_ERROR_FAILED,
			     "Cannot delete %s: %s",
			     PK_OFFLINE_PREPARED_UPGRADE_FILENAME,
			     error_local->message);
		return FALSE;
	}

	return TRUE;
}
Example #3
0
/**
 * pk_offline_auth_set_action:
 * @action: a #PkOfflineAction, e.g. %PK_OFFLINE_ACTION_REBOOT
 * @error: A #GError or %NULL
 *
 * Sets the action to be done after the offline action has been performed.
 *
 * Return value: %TRUE for success, else %FALSE and @error set
 *
 * Since: 0.9.6
 **/
gboolean
pk_offline_auth_set_action (PkOfflineAction action, GError **error)
{
	const gchar *action_str;
	g_autoptr(GError) error_local = NULL;

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

	if (action == PK_OFFLINE_ACTION_UNKNOWN) {
		g_set_error (error,
			     PK_OFFLINE_ERROR,
			     PK_OFFLINE_ERROR_INVALID_VALUE,
			     "Failed to set unknown %i", action);
		return FALSE;
	}
	if (action == PK_OFFLINE_ACTION_UNSET)
		return pk_offline_auth_cancel (error);

	action_str = pk_offline_action_to_string (action);
	if (action_str == NULL) {
		g_set_error (error,
			     PK_OFFLINE_ERROR,
			     PK_OFFLINE_ERROR_FAILED,
			     "Failed to convert %i", action);
		return FALSE;
	}
	if (!g_file_set_contents (PK_OFFLINE_ACTION_FILENAME,
				  action_str, -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;
}